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. diff --git a/geeknote/argparser.py b/geeknote/argparser.py index 9e97c52..da07cb6 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": { @@ -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,12 +144,24 @@ "help": "Search by content, not by title.", "value": True, "default": False}, + "--guid": {"altName": "-id", + "help": "Replace ID with GUID " + "of each note in results.", + "value": True, + "default": False}, } }, # 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.", @@ -162,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.", @@ -438,4 +467,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..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() @@ -741,34 +741,40 @@ 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, with_tags=None, with_notebook=None, + count=None, guid=None): request = self._createSearchRequest(search, tags, notebooks, date, exact_entry, @@ -804,8 +810,11 @@ 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, 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 6c3e27b..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): + 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" % ( - str(key).rjust(3, " "), + 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: 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 "<Tag('{0}')>".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 "<Note('{0}')>".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): """