Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit e86ccae

Browse files
committed
Added a option to show GUID for editing/removing by it
1 parent 8489a87 commit e86ccae

File tree

4 files changed

+78
-23
lines changed

4 files changed

+78
-23
lines changed

geeknote/argparser.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"firstArg": "--note",
5959
"arguments": {
6060
"--note": {"altName": "-n",
61-
"help": "The name or ID from the "
61+
"help": "The name or GUID or ID from the "
6262
"previous search of a note to edit."},
6363
"--title": {"altName": "-t",
6464
"help": "Set new title of the note."},
@@ -76,7 +76,7 @@
7676
"firstArg": "--note",
7777
"arguments": {
7878
"--note": {"altName": "-n",
79-
"help": "The name or ID from the previous "
79+
"help": "The name or GUID or ID from the previous "
8080
"search of a note to remove."},
8181
},
8282
"flags": {
@@ -91,7 +91,7 @@
9191
"firstArg": "--note",
9292
"arguments": {
9393
"--note": {"altName": "-n",
94-
"help": "The name or ID from the previous "
94+
"help": "The name or GUID or ID from the previous "
9595
"search of a note to show."},
9696
},
9797
"flags": {
@@ -134,6 +134,11 @@
134134
"help": "Search by content, not by title.",
135135
"value": True,
136136
"default": False},
137+
"--guid": {"altName": "-gi",
138+
"help": "Replace ID with GUID "
139+
"of each note in results.",
140+
"value": True,
141+
"default": False},
137142
}
138143
},
139144

@@ -438,4 +443,4 @@ def printHelp(self):
438443
out.printLine("Available flags:")
439444
for flag in self.CMD_FLAGS:
440445
out.printLine("%s : %s" % (flag.rjust(tab, " "),
441-
self.CMD_FLAGS[flag]['help']))
446+
self.CMD_FLAGS[flag]['help']))

geeknote/geeknote.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -741,34 +741,39 @@ def _searchNote(self, note):
741741
note = tools.strip(note)
742742

743743
# load search result
744-
result = self.getStorage().getSearch()
745-
if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes):
746-
note = result.notes[int(note) - 1]
744+
result = self.getStorage().getNote(note)
745+
if result:
746+
note = result
747747

748748
else:
749-
request = self._createSearchRequest(search=note)
749+
result = self.getStorage().getSearch()
750+
if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes):
751+
note = result.notes[int(note) - 1]
750752

751-
logging.debug("Search notes: %s" % request)
752-
result = self.getEvernote().findNotes(request, 20)
753+
else:
754+
request = self._createSearchRequest(search=note)
753755

754-
logging.debug("Search notes result: %s" % str(result))
755-
if result.totalNotes == 0:
756-
out.failureMessage("Notes have not been found.")
757-
return tools.exitErr()
756+
logging.debug("Search notes: %s" % request)
757+
result = self.getEvernote().findNotes(request, 20)
758758

759-
elif result.totalNotes == 1 or self.selectFirstOnUpdate:
760-
note = result.notes[0]
759+
logging.debug("Search notes result: %s" % str(result))
760+
if result.totalNotes == 0:
761+
out.failureMessage("Notes have not been found.")
762+
return tools.exitErr()
761763

762-
else:
763-
logging.debug("Choose notes: %s" % str(result.notes))
764-
note = out.SelectSearchResult(result.notes)
764+
elif result.totalNotes == 1 or self.selectFirstOnUpdate:
765+
note = result.notes[0]
766+
767+
else:
768+
logging.debug("Choose notes: %s" % str(result.notes))
769+
note = out.SelectSearchResult(result.notes)
765770

766771
logging.debug("Selected note: %s" % str(note))
767772
return note
768773

769774
def find(self, search=None, tags=None, notebooks=None,
770775
date=None, exact_entry=None, content_search=None,
771-
with_url=None, count=None, ):
776+
with_url=None, count=None, guid=None):
772777

773778
request = self._createSearchRequest(search, tags, notebooks,
774779
date, exact_entry,
@@ -804,8 +809,10 @@ def find(self, search=None, tags=None, notebooks=None,
804809
# save search result
805810
# print result
806811
self.getStorage().setSearch(result)
812+
for note in result.notes:
813+
self.getStorage().setNote(note)
807814

808-
out.SearchResult(result.notes, request, showUrl=with_url)
815+
out.SearchResult(result.notes, request, showUrl=with_url, showGUID=guid)
809816

810817
def _createSearchRequest(self, search=None, tags=None,
811818
notebooks=None, date=None,

geeknote/out.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def separator(symbol="", title=""):
226226

227227
@preloaderStop
228228
def printList(listItems, title="", showSelector=False,
229-
showByStep=20, showUrl=False):
229+
showByStep=20, showUrl=False, showGUID=False):
230230

231231
if title:
232232
separator("=", title)
@@ -237,7 +237,7 @@ def printList(listItems, title="", showSelector=False,
237237
key += 1
238238

239239
printLine("%s : %s%s%s" % (
240-
str(key).rjust(3, " "),
240+
item.guid if showGUID and hasattr(item, 'guid') else str(key).rjust(3, " "),
241241
printDate(item.created).ljust(18, " ") if hasattr(item, 'created') else '',
242242
item.title if hasattr(item, 'title') else item.name,
243243
" " + (">>> " + config.NOTE_URL % item.guid) if showUrl else '',))

geeknote/storage.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ def __repr__(self):
8181
return "<Tag('{0}')>".format(self.tag)
8282

8383

84+
class Note(Base):
85+
__tablename__ = 'notes'
86+
87+
id = Column(Integer, primary_key=True)
88+
guid = Column(String(1000))
89+
obj = Column(PickleType())
90+
timestamp = Column(DateTime(), nullable=False)
91+
92+
def __init__(self, guid, obj):
93+
self.guid = guid
94+
self.obj = obj
95+
self.timestamp = datetime.datetime.now()
96+
97+
def __repr__(self):
98+
return "<Note('{0}')>".format(self.timestamp)
99+
100+
84101
class Search(Base):
85102
__tablename__ = 'search'
86103

@@ -359,6 +376,32 @@ def getNotebooks(self):
359376
result[item.guid] = item.name
360377
return result
361378

379+
@logging
380+
def setNote(self, obj):
381+
"""
382+
Set note.
383+
"""
384+
for item in self.session.query(Note).filter(Note.guid == obj.guid).all():
385+
self.session.delete(item)
386+
387+
note = pickle.dumps(obj)
388+
instance = Note(obj.guid, note)
389+
self.session.add(instance)
390+
391+
self.session.commit()
392+
return True
393+
394+
@logging
395+
def getNote(self, guid):
396+
"""
397+
Get note by GUID.
398+
"""
399+
note = self.session.query(Note).filter(Note.guid == guid).first()
400+
if note:
401+
return pickle.loads(note.obj)
402+
else:
403+
return None
404+
362405
@logging
363406
def setSearch(self, search_obj):
364407
"""

0 commit comments

Comments
 (0)