From e86ccae32b657583cadc78fe6ab1906be1293489 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sat, 7 Nov 2015 11:13:16 +0900 Subject: [PATCH 1/3] Added a option to show GUID for editing/removing by it --- geeknote/argparser.py | 13 +++++++++---- geeknote/geeknote.py | 41 ++++++++++++++++++++++++----------------- geeknote/out.py | 4 ++-- geeknote/storage.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/geeknote/argparser.py b/geeknote/argparser.py index 9e97c52..dc43001 100644 --- a/geeknote/argparser.py +++ b/geeknote/argparser.py @@ -58,7 +58,7 @@ "firstArg": "--note", "arguments": { "--note": {"altName": "-n", - "help": "The name or ID from the " + "help": "The name or GUID or ID from the " "previous search of a note to edit."}, "--title": {"altName": "-t", "help": "Set new title of the note."}, @@ -76,7 +76,7 @@ "firstArg": "--note", "arguments": { "--note": {"altName": "-n", - "help": "The name or ID from the previous " + "help": "The name or GUID or ID from the previous " "search of a note to remove."}, }, "flags": { @@ -91,7 +91,7 @@ "firstArg": "--note", "arguments": { "--note": {"altName": "-n", - "help": "The name or ID from the previous " + "help": "The name or GUID or ID from the previous " "search of a note to show."}, }, "flags": { @@ -134,6 +134,11 @@ "help": "Search by content, not by title.", "value": True, "default": False}, + "--guid": {"altName": "-gi", + "help": "Replace ID with GUID " + "of each note in results.", + "value": True, + "default": False}, } }, @@ -438,4 +443,4 @@ def printHelp(self): out.printLine("Available flags:") for flag in self.CMD_FLAGS: out.printLine("%s : %s" % (flag.rjust(tab, " "), - self.CMD_FLAGS[flag]['help'])) \ No newline at end of file + self.CMD_FLAGS[flag]['help'])) diff --git a/geeknote/geeknote.py b/geeknote/geeknote.py index 42ca567..8e98d64 100644 --- a/geeknote/geeknote.py +++ b/geeknote/geeknote.py @@ -741,34 +741,39 @@ def _searchNote(self, note): note = tools.strip(note) # load search result - result = self.getStorage().getSearch() - if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes): - note = result.notes[int(note) - 1] + result = self.getStorage().getNote(note) + if result: + note = result else: - request = self._createSearchRequest(search=note) + result = self.getStorage().getSearch() + if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes): + note = result.notes[int(note) - 1] - logging.debug("Search notes: %s" % request) - result = self.getEvernote().findNotes(request, 20) + else: + request = self._createSearchRequest(search=note) - logging.debug("Search notes result: %s" % str(result)) - if result.totalNotes == 0: - out.failureMessage("Notes have not been found.") - return tools.exitErr() + logging.debug("Search notes: %s" % request) + result = self.getEvernote().findNotes(request, 20) - elif result.totalNotes == 1 or self.selectFirstOnUpdate: - note = result.notes[0] + logging.debug("Search notes result: %s" % str(result)) + if result.totalNotes == 0: + out.failureMessage("Notes have not been found.") + return tools.exitErr() - else: - logging.debug("Choose notes: %s" % str(result.notes)) - note = out.SelectSearchResult(result.notes) + elif result.totalNotes == 1 or self.selectFirstOnUpdate: + note = result.notes[0] + + else: + logging.debug("Choose notes: %s" % str(result.notes)) + note = out.SelectSearchResult(result.notes) logging.debug("Selected note: %s" % str(note)) return note def find(self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None, - with_url=None, count=None, ): + with_url=None, count=None, guid=None): request = self._createSearchRequest(search, tags, notebooks, date, exact_entry, @@ -804,8 +809,10 @@ def find(self, search=None, tags=None, notebooks=None, # save search result # print result self.getStorage().setSearch(result) + for note in result.notes: + self.getStorage().setNote(note) - out.SearchResult(result.notes, request, showUrl=with_url) + out.SearchResult(result.notes, request, showUrl=with_url, showGUID=guid) def _createSearchRequest(self, search=None, tags=None, notebooks=None, date=None, diff --git a/geeknote/out.py b/geeknote/out.py index 6c3e27b..11d962b 100644 --- a/geeknote/out.py +++ b/geeknote/out.py @@ -226,7 +226,7 @@ def separator(symbol="", title=""): @preloaderStop def printList(listItems, title="", showSelector=False, - showByStep=20, showUrl=False): + showByStep=20, showUrl=False, showGUID=False): if title: separator("=", title) @@ -237,7 +237,7 @@ def printList(listItems, title="", showSelector=False, key += 1 printLine("%s : %s%s%s" % ( - str(key).rjust(3, " "), + item.guid if showGUID and hasattr(item, 'guid') else str(key).rjust(3, " "), printDate(item.created).ljust(18, " ") if hasattr(item, 'created') else '', item.title if hasattr(item, 'title') else item.name, " " + (">>> " + config.NOTE_URL % item.guid) if showUrl else '',)) diff --git a/geeknote/storage.py b/geeknote/storage.py index 0e4ee42..a22096e 100644 --- a/geeknote/storage.py +++ b/geeknote/storage.py @@ -81,6 +81,23 @@ def __repr__(self): return "".format(self.tag) +class Note(Base): + __tablename__ = 'notes' + + id = Column(Integer, primary_key=True) + guid = Column(String(1000)) + obj = Column(PickleType()) + timestamp = Column(DateTime(), nullable=False) + + def __init__(self, guid, obj): + self.guid = guid + self.obj = obj + self.timestamp = datetime.datetime.now() + + def __repr__(self): + return "".format(self.timestamp) + + class Search(Base): __tablename__ = 'search' @@ -359,6 +376,32 @@ def getNotebooks(self): result[item.guid] = item.name return result + @logging + def setNote(self, obj): + """ + Set note. + """ + for item in self.session.query(Note).filter(Note.guid == obj.guid).all(): + self.session.delete(item) + + note = pickle.dumps(obj) + instance = Note(obj.guid, note) + self.session.add(instance) + + self.session.commit() + return True + + @logging + def getNote(self, guid): + """ + Get note by GUID. + """ + note = self.session.query(Note).filter(Note.guid == guid).first() + if note: + return pickle.loads(note.obj) + else: + return None + @logging def setSearch(self, search_obj): """ From b4059324b22f9d2a8c956bf1ee8757ce339bd6a2 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sat, 7 Nov 2015 22:58:12 +0900 Subject: [PATCH 2/3] Added a option to show GUID of tag/notebook --- geeknote/argparser.py | 26 +++++++++++++++++++++++++- geeknote/geeknote.py | 14 ++++++++------ geeknote/out.py | 7 +++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/geeknote/argparser.py b/geeknote/argparser.py index dc43001..da07cb6 100644 --- a/geeknote/argparser.py +++ b/geeknote/argparser.py @@ -125,6 +125,16 @@ "in results to Evernote web-version.", "value": True, "default": False}, + "--with-tags": {"altName": "-wt", + "help": "Add tag list of each note " + "in results.", + "value": True, + "default": False}, + "--with-notebook": {"altName": "-wn", + "help": "Add notebook of each note " + "in results.", + "value": True, + "default": False}, "--exact-entry": {"altName": "-ee", "help": "Search for exact " "entry of the request.", @@ -134,7 +144,7 @@ "help": "Search by content, not by title.", "value": True, "default": False}, - "--guid": {"altName": "-gi", + "--guid": {"altName": "-id", "help": "Replace ID with GUID " "of each note in results.", "value": True, @@ -145,6 +155,13 @@ # Notebooks "notebook-list": { "help": "Show the list of existing notebooks in your Evernote.", + "flags": { + "--guid": {"altName": "-id", + "help": "Replace ID with GUID " + "of each notebook in results.", + "value": True, + "default": False}, + } }, "notebook-create": { "help": "Create new notebook.", @@ -167,6 +184,13 @@ # Tags "tag-list": { "help": "Show the list of existing tags in your Evernote.", + "flags": { + "--guid": {"altName": "-id", + "help": "Replace ID with GUID " + "of each note in results.", + "value": True, + "default": False}, + } }, "tag-create": { "help": "Create new tag.", diff --git a/geeknote/geeknote.py b/geeknote/geeknote.py index 8e98d64..53a7bfc 100644 --- a/geeknote/geeknote.py +++ b/geeknote/geeknote.py @@ -451,9 +451,9 @@ def settings(self, editor=None): class Tags(GeekNoteConnector): """ Work with auth Notebooks """ - def list(self): + def list(self, guid=None): result = self.getEvernote().findTags() - out.printList(result) + out.printList(result, showGUID=guid) def create(self, title): self.connectToEvertone() @@ -511,9 +511,9 @@ def _searchTag(self, tag): class Notebooks(GeekNoteConnector): """ Work with auth Notebooks """ - def list(self): + def list(self, guid=None): result = self.getEvernote().findNotebooks() - out.printList(result) + out.printList(result, showGUID=guid) def create(self, title): self.connectToEvertone() @@ -773,7 +773,8 @@ def _searchNote(self, note): def find(self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None, - with_url=None, count=None, guid=None): + with_url=None, with_tags=None, with_notebook=None, + count=None, guid=None): request = self._createSearchRequest(search, tags, notebooks, date, exact_entry, @@ -812,7 +813,8 @@ def find(self, search=None, tags=None, notebooks=None, for note in result.notes: self.getStorage().setNote(note) - out.SearchResult(result.notes, request, showUrl=with_url, showGUID=guid) + out.SearchResult(result.notes, request, showUrl=with_url, showTags=with_tags, + showNotebook=with_notebook, showGUID=guid) def _createSearchRequest(self, search=None, tags=None, notebooks=None, date=None, diff --git a/geeknote/out.py b/geeknote/out.py index 11d962b..bd1c889 100644 --- a/geeknote/out.py +++ b/geeknote/out.py @@ -226,7 +226,8 @@ def separator(symbol="", title=""): @preloaderStop def printList(listItems, title="", showSelector=False, - showByStep=20, showUrl=False, showGUID=False): + showByStep=20, showUrl=False, showTags=False, + showNotebook=False, showGUID=False): if title: separator("=", title) @@ -236,10 +237,12 @@ def printList(listItems, title="", showSelector=False, for key, item in enumerate(listItems): key += 1 - printLine("%s : %s%s%s" % ( + printLine("%s : %s%s%s%s%s" % ( item.guid if showGUID and hasattr(item, 'guid') else str(key).rjust(3, " "), printDate(item.created).ljust(18, " ") if hasattr(item, 'created') else '', item.title if hasattr(item, 'title') else item.name, + "".join( map(lambda s:" #"+s, item.tagGuids) ) if showTags and hasattr(item, 'tagGuids') and item.tagGuids else '', + " @"+item.notebookGuid if showNotebook and hasattr(item, 'notebookGuid') else '', " " + (">>> " + config.NOTE_URL % item.guid) if showUrl else '',)) if key % showByStep == 0 and key < total: From 74651daccfe092fe76ff497b0fd330c8aa1bad16 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Mon, 9 Nov 2015 22:03:28 +0900 Subject: [PATCH 3/3] Update README about addition of the option to show GUID --- README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 07c009e..a088ad4 100755 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ This command allows us to create a new note in Evernote. Geeknote has designed f With Geeknote you can edit your notes in Evernote using any editor you like. It could be nano, vi, vim etc ... You can edit notes right in console! ### Synopsis - $ geeknote edit --note + $ geeknote edit --note <title or GUID of note which to edit> [--content <a new content or "WRITE">] [--title <the new title>] [--tags <new list of data>] @@ -176,6 +176,9 @@ You can easily search notes in Evernote with Geeknote and get results in console [--exact-entry] [--content-search] [--url-only] + [--with-tags] + [--with-notebook] + [--guid] ### Description With **find** you can make a search through your Evernote. It has an usefull options that allow you to make search more detail. Important notice, that Geeknote remembers the result of the last search. So, you can use the number of the note's position to make some actions that Geeknote can. For example: @@ -215,6 +218,15 @@ That will show you the note "Shopping list 25.04.2012". --url-only : Show results as a list of URLs to the every note in Evernote's web-client. +--with-tags +: Show tags of the note after note title. + +--with-notebook +: Show notebook which contains the note after note title. + +--guid +: Show GUID of the note as substitute for result index. + ### Examples $ geeknote find --search "How to patch KDE2" --notebooks "jokes" --date 25.03.2012-25.06.2012 $ geeknote find --search "apt-get install apache nginx" --content-search --notebooks "manual" @@ -223,7 +235,7 @@ That will show you the note "Shopping list 25.04.2012". You can output any note in console using command *show* - that is add-on for *find*. When you use *show* it make search previously, and if the count of results more then 1, Geeknote will ask you to make a choise. ### Synopsis - $ geeknote show <text to search and show> + $ geeknote show <text or GUID to search and show> That is really simple, so doesn't need any descriptions. Just some examples: ### Examples $ geeknote show "Shop*" @@ -249,7 +261,7 @@ As we mentioned before, *show* can use the results of previous search, so if you You can remove notes with Geeknotes from Evernote. ### Synopsis - $ geeknote remove --notebook <note name> + $ geeknote remove --notebook <note name or GUID> [--force] ### Options @@ -266,7 +278,11 @@ You can remove notes with Geeknotes from Evernote. ## Notebooks: show the list of notebooks Geeknote can display the list of all notebooks you have in Evernote. ### Synopsis - $ geeknote notebook-list + $ geeknote notebook-list [--guid] + +### Options +--guid +: Show GUID of the notebook as substitute for result index. ## Notebooks: create the notebook With Geeknote you can create notebooks in Evernote right in console! @@ -301,7 +317,11 @@ With Geeknote it's possible to rename existing notebooks in Evernote. ## Tags: show the list of tags You can get the list of all tags you have in Evernote. ### Synopsis - $ geeknote tag-list + $ geeknote tag-list [--guid] + +### Options +--guid +: Show GUID of the tag as substitute for result index. ## Tags: create a new tag Usually tags are created with publishing new note. But if you need, you can create a new tag with Geeknote.