-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleNoteManagerClass.py
More file actions
174 lines (131 loc) · 5.3 KB
/
SimpleNoteManagerClass.py
File metadata and controls
174 lines (131 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from tkinter import NONE
import simplenote
class SimpleNoteManagerClass():
def __init__(self,username, password):
#self.sn = sn
self.sn = simplenote.Simplenote(username, password)
def findNote(self, tag):
'''return note object, specifically the first one with a given tag'''
#note = self.sn.get_note_list(data=True, since=None, tags=[tag])[0][0]
(note_list,success) = self.sn.get_note_list(data=True, since=None, tags=[tag])
#if the notelist is retrieved and nonempty, return note
if ((success == 0) and (len(note_list) != 0)):
note = note_list[0]
return note
else:
return None
def createNote(self, title, tag, pinned=False):
'''create an entirely new note'''
#generate the note
note_content = "# {} \r\n ".format(title)
note_system_tags = ['markdown']
if (pinned):
note_system_tags.append('pinned')
note = {'content' : note_content, 'tags' : [tag], 'systemtags': note_system_tags}
#create the note online, check for success
(note,success) = self.sn.add_note(note)
if (success == 0):
return note
else:
return None
def addContent(self, note, newcontent, listitem=False, debug = False):
'''add items to the passed note, add it as a listitem if listitem==True'''
#if the note doesn't exist, say so
if (note == None):
return False
#retrieve content and append new content
note_content = note['content']
if (listitem):
new_note_content = "{} \r\n- [ ] {}".format(note_content, newcontent)
else:
new_note_content = "{} \r\n{}".format(note_content, newcontent)
#update the note online with the new content
note['content'] = new_note_content
self.sn.update_note(note)
if (debug):
print(note_content['content'])
#if everything goes well, say so
return True
def removeCheckedItems(self,note):
'''remove all lines with checked boxes from passed note'''
#if the note doesn't exist, say so
if (note == None):
return False
#search through each line
note_content = note['content']
note_lines = note_content.split("\n")
#keep each unchecked line
new_lines = []
for line in note_lines:
#print(line[:5])
if (line[:5] != '- [x]'):
new_lines.append(line)
#update the note
new_note_content = "\n".join(new_lines)
note['content'] = new_note_content
self.sn.update_note(note)
#if everything goes well, say so
return True
def searchNote(self, note, search_term):
'''search each line of a note for term, return each positive line's (index, content)'''
#if the note doesn't exist, say so
if (note == None):
return (False,[])
#go through each line
note_content = note['content']
note_lines = note_content.split("\n")
found_lines = []
for i in range(len(note_lines)):
#store each successful line
if (note_lines[i].lower().find(search_term.lower()) != -1):
found_lines.append((i,note_lines[i]))
#if all goes well, return true and the found lines lists
return (True, found_lines)
def removeSearchLine(self, note, search_term):
'''remove every line with containing searchitem'''
#if the note doesn't exist, say so
if (note == None):
return False
#find lines containing search_term
(success,found_lines) = self.searchNote(note, search_term)
#if search failed, say so
if not (success):
return False
#remove lines with search_term
note_content = note['content']
note_lines = note_content.split("\n")
for line in found_lines:
note_lines.pop(line[0])
#update note online
new_note_content = "\n".join(note_lines)
note['content'] = new_note_content
self.sn.update_note(note)
#if everything goes well, say so
return True
def getContentLines(self, note):
content = note['content']
lines = content.split('\n')
parsedlines = []
for line in lines:
if (line[:1] == '#'):
parsedlines.append(line[1:].lower())
elif ((line[:5] == '- [x]') or (line[:5] == '- [ ]')):
parsedlines.append(line[5:].lower())
else:
parsedlines.append(line.lower())
return parsedlines
if __name__ == '__main__':
pass
#sn = SimpleNoteManagerClass(u,p)
#shopping_list_note = sn.findNote('ShoppingList')
# simplenoteinstance = simplenote.Simplenote(username, password)
#sn.addShoppingListItem("heres hoping")
#sn.removeCheckedItems()
#sn.searchShoppingList("moose")
# sn.removeSearchLine(shopping_list_note,"Remove")
#sn.addContent(shopping_list_note,"Woot I do say", True)
# sn.removeCheckedItems(shopping_list_note)
# print(shopping_list_note)
#note = sn.findNote('space')
#print(note)
#print(sn.createNote("Whats up space invaders!!!", "space invaders"))