Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a option to show GUID #332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <title of note which to edit>
$ 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>]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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*"
Expand All @@ -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

Expand All @@ -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!
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 33 additions & 4 deletions geeknote/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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.",
Expand All @@ -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.",
Expand All @@ -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.",
Expand Down Expand Up @@ -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']))
self.CMD_FLAGS[flag]['help']))
51 changes: 30 additions & 21 deletions geeknote/geeknote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions geeknote/out.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
43 changes: 43 additions & 0 deletions geeknote/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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):
"""
Expand Down