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

Commit bb360cd

Browse files
committed
Merge branch 'option-guid' of https://github.com/aki2o/geeknote
2 parents 3dbf09a + 74651da commit bb360cd

File tree

5 files changed

+134
-41
lines changed

5 files changed

+134
-41
lines changed

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ The main functionality that we need is creating notes in Evernote.
136136
[--created <date and time>]
137137
[--resource <attachment filename>]
138138
[--notebook <notebook where to save>]
139-
[--reminder <date and time>]
139+
[--reminder <date and time>]
140140
### Options
141141

142142
--title &lt;title&gt;
@@ -188,14 +188,14 @@ Creating a new note and editing content in editor:
188188
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!
189189

190190
### Synopsis
191-
$ geeknote edit --note <title of note which to edit>
191+
$ geeknote edit --note <title or GUID of note to edit>
192192
[--content <new content or "WRITE">]
193193
[--title <the new title>]
194194
[--tags <new list of data>]
195195
[--created <date and time>]
196196
[--resource <attachment filename>]
197197
[--notebook <new notebook>]
198-
[--reminder <date and time>]
198+
[--reminder <date and time>]
199199

200200
### Options
201201

@@ -253,6 +253,9 @@ You can easily search notes in Evernote with Geeknote and get results in console
253253
[--url-only]
254254
[--reminders-only]
255255
[--ignore-completed]
256+
[--with-tags]
257+
[--with-notebook]
258+
[--guid]
256259
### Description
257260
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.
258261
For example:
@@ -293,12 +296,19 @@ That will show you the note "Shopping list 25.04.2012".
293296
: Show results as a list of URLs to the every note in Evernote's web-client.
294297

295298
--reminders-only
296-
: Include only notes with a reminder.
299+
: Include only notes with a reminder.
297300

298301
--ignore-completed
299-
: Include only unfinished reminders.
302+
: Include only unfinished reminders.
300303

304+
--with-tags
305+
: Show tags of the note after note title.
301306

307+
--with-notebook
308+
: Show notebook which contains the note after note title.
309+
310+
--guid
311+
: Show GUID of the note as substitute for result index.
302312

303313
### Examples
304314
$ geeknote find --search "How to patch KDE2" --notebooks "jokes" --date 25.03.2012-25.06.2012
@@ -308,7 +318,7 @@ That will show you the note "Shopping list 25.04.2012".
308318
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.
309319

310320
### Synopsis
311-
$ geeknote show <text to search and show>
321+
$ geeknote show <text or GUID to search and show>
312322
That is really simple, so doesn't need any descriptions. Just some examples:
313323
### Examples
314324
$ geeknote show "Shop*"
@@ -334,7 +344,7 @@ As we mentioned before, *show* can use the results of previous search, so if you
334344
You can remove notes with Geeknotes from Evernote.
335345

336346
### Synopsis
337-
$ geeknote remove --notebook <note name>
347+
$ geeknote remove --notebook <note name or GUID>
338348
[--force]
339349
### Options
340350

@@ -351,7 +361,11 @@ You can remove notes with Geeknotes from Evernote.
351361
## Notebooks: show the list of notebooks
352362
Geeknote can display the list of all notebooks you have in Evernote.
353363
### Synopsis
354-
$ geeknote notebook-list
364+
$ geeknote notebook-list [--guid]
365+
366+
### Options
367+
--guid
368+
: Show GUID of the notebook as substitute for result index.
355369

356370
## Notebooks: create the notebook
357371
With Geeknote you can create notebooks in Evernote right in console!
@@ -386,7 +400,11 @@ With Geeknote it's possible to rename existing notebooks in Evernote.
386400
## Tags: show the list of tags
387401
You can get the list of all tags you have in Evernote.
388402
### Synopsis
389-
$ geeknote tag-list
403+
$ geeknote tag-list [--guid]
404+
405+
### Options
406+
--guid
407+
: Show GUID of the tag as substitute for result index.
390408

391409
## Tags: create a new tag
392410
Usually tags are created with publishing new note. But if you need, you can create a new tag with Geeknote.

geeknote/argparser.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"firstArg": "--note",
8989
"arguments": {
9090
"--note": {"altName": "-n",
91-
"help": "The name or ID from the "
91+
"help": "The name or GUID or ID from the "
9292
"previous search of a note to edit.",
9393
"required": True},
9494
"--title": {"altName": "-t",
@@ -129,7 +129,7 @@
129129
"firstArg": "--note",
130130
"arguments": {
131131
"--note": {"altName": "-n",
132-
"help": "The name or ID from the previous "
132+
"help": "The name or GUID or ID from the previous "
133133
"search of a note to remove.",
134134
"required": True},
135135
},
@@ -145,7 +145,7 @@
145145
"firstArg": "--note",
146146
"arguments": {
147147
"--note": {"altName": "-n",
148-
"help": "The name or ID from the previous "
148+
"help": "The name or GUID or ID from the previous "
149149
"search of a note to show.",
150150
"required": True},
151151
},
@@ -180,15 +180,26 @@
180180
"in results to Evernote web-version.",
181181
"value": True,
182182
"default": False},
183+
"--with-tags": {"altName": "-wt",
184+
"help": "Add tag list of each note in results.",
185+
"value": True,
186+
"default": False},
187+
"--with-notebook": {"altName": "-wn",
188+
"help": "Add notebook of each note in results.",
189+
"value": True,
190+
"default": False},
183191
"--exact-entry": {"altName": "-ee",
184-
"help": "Search for exact "
185-
"entry of the request.",
192+
"help": "Search for exact entry of the request.",
186193
"value": True,
187194
"default": False},
188195
"--content-search": {"altName": "-cs",
189196
"help": "Search by content, not by title.",
190197
"value": True,
191198
"default": False},
199+
"--guid": {"altName": "-id",
200+
"help": "Replace ID with GUID of each note in results.",
201+
"value": True,
202+
"default": False},
192203
"--reminders-only": {"altName": "-R",
193204
"help": "Include only notes with a reminder.",
194205
"value": True,
@@ -238,6 +249,13 @@
238249
# Notebooks
239250
"notebook-list": {
240251
"help": "Show the list of existing notebooks in your Evernote.",
252+
"flags": {
253+
"--guid": {"altName": "-id",
254+
"help": "Replace ID with GUID "
255+
"of each notebook in results.",
256+
"value": True,
257+
"default": False},
258+
}
241259
},
242260
"notebook-create": {
243261
"help": "Create new notebook.",
@@ -261,6 +279,12 @@
261279
# Tags
262280
"tag-list": {
263281
"help": "Show the list of existing tags in your Evernote.",
282+
"flags": {
283+
"--guid": {"altName": "-id",
284+
"help": "Replace ID with GUID of each note in results.",
285+
"value": True,
286+
"default": False},
287+
}
264288
},
265289
"tag-create": {
266290
"help": "Create new tag.",

geeknote/geeknote.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ def settings(self, editor=None, extras=None, note_ext=None):
600600
class Tags(GeekNoteConnector):
601601
""" Work with auth Notebooks """
602602

603-
def list(self):
603+
def list(self, guid=None):
604604
result = self.getEvernote().findTags()
605-
out.printList(result)
605+
out.printList(result, showGUID=guid)
606606

607607
def create(self, title):
608608
self.connectToEvernote()
@@ -661,9 +661,9 @@ def _searchTag(self, tag):
661661
class Notebooks(GeekNoteConnector):
662662
""" Work with auth Notebooks """
663663

664-
def list(self):
664+
def list(self, guid=None):
665665
result = self.getEvernote().findNotebooks()
666-
out.printList(result)
666+
out.printList(result, showGUID=guid)
667667

668668
def create(self, title, stack=None):
669669
self.connectToEvernote()
@@ -943,35 +943,37 @@ def _searchNote(self, note):
943943
note = tools.strip(note)
944944

945945
# load search result
946-
result = self.getStorage().getSearch()
947-
if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes):
948-
note = result.notes[int(note) - 1]
946+
result = self.getStorage().getNote(note)
947+
if result:
948+
note = result
949949

950950
else:
951-
request = self._createSearchRequest(search=note)
952-
953-
logging.debug("Search notes: %s" % request)
954-
result = self.getEvernote().findNotes(request, 20)
955-
956-
logging.debug("Search notes result: %s" % str(result))
957-
if result.totalNotes == 0:
958-
out.failureMessage("Notes have not been found.")
959-
return tools.exitErr()
960-
961-
elif result.totalNotes == 1 or self.selectFirstOnUpdate:
962-
note = result.notes[0]
963-
951+
result = self.getStorage().getSearch()
952+
if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes):
953+
note = result.notes[int(note) - 1]
964954
else:
965-
logging.debug("Choose notes: %s" % str(result.notes))
966-
note = out.SelectSearchResult(result.notes)
955+
request = self._createSearchRequest(search=note)
956+
logging.debug("Search notes: %s" % request)
957+
result = self.getEvernote().findNotes(request, 20)
958+
logging.debug("Search notes result: %s" % str(result))
959+
if result.totalNotes == 0:
960+
out.failureMessage("Notes have not been found.")
961+
return tools.exitErr()
962+
elif result.totalNotes == 1 or self.selectFirstOnUpdate:
963+
note = result.notes[0]
964+
965+
else:
966+
logging.debug("Choose notes: %s" % str(result.notes))
967+
note = out.SelectSearchResult(result.notes)
967968

968969
logging.debug("Selected note: %s" % str(note))
969970
note = self.getEvernote().getNote(note.guid)
970971
return note
971972

972973
def find(self, search=None, tags=None, notebooks=None,
973974
date=None, exact_entry=None, content_search=None,
974-
with_url=None, count=None, ignore_completed=None, reminders_only=None,):
975+
with_url=None, with_tags=None, with_notebook=None,
976+
count=None, ignore_completed=None, reminders_only=None, guid=None):
975977

976978
request = self._createSearchRequest(search, tags, notebooks,
977979
date, exact_entry,
@@ -995,8 +997,11 @@ def find(self, search=None, tags=None, notebooks=None,
995997
# save search result
996998
# print result
997999
self.getStorage().setSearch(result)
1000+
for note in result.notes:
1001+
self.getStorage().setNote(note)
9981002

999-
out.SearchResult(result.notes, request, showUrl=with_url)
1003+
out.SearchResult(result.notes, request, showUrl=with_url, showTags=with_tags,
1004+
showNotebook=with_notebook, showGUID=guid)
10001005

10011006
def dedup(self, search=None, tags=None, notebooks=None,
10021007
date=None, exact_entry=None, content_search=None,

geeknote/out.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def separator(symbol="", title=""):
234234

235235
@preloaderStop
236236
def printList(listItems, title="", showSelector=False,
237-
showByStep=0, showUrl=False):
237+
showByStep=0, showUrl=False, showTags=False,
238+
showNotebook=False, showGUID=False):
238239

239240
if title:
240241
separator("=", title)
@@ -244,11 +245,13 @@ def printList(listItems, title="", showSelector=False,
244245
for key, item in enumerate(listItems):
245246
key += 1
246247

247-
printLine("%s : %s%s%s%s" % (
248-
str(key).rjust(3, " "),
248+
printLine("%s : %s%s%s%s%s%s" % (
249+
item.guid if showGUID and hasattr(item, 'guid') else str(key).rjust(3, " "),
249250
printDate(item.created).ljust(18, " ") if hasattr(item, 'created') else '',
250251
printDate(item.updated).ljust(18, " ") if hasattr(item, 'updated') else '',
251252
item.title if hasattr(item, 'title') else item.name,
253+
"".join( map(lambda s:" #"+s, item.tagGuids) ) if showTags and hasattr(item, 'tagGuids') and item.tagGuids else '',
254+
" @"+item.notebookGuid if showNotebook and hasattr(item, 'notebookGuid') else '',
252255
" " + (">>> " + config.NOTE_URL % item.guid) if showUrl else '',))
253256

254257
if showByStep != 0 and key % showByStep == 0 and key < total:

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

@@ -372,6 +389,32 @@ def getNotebooks(self):
372389
result[item.guid] = item.name
373390
return result
374391

392+
@logging
393+
def setNote(self, obj):
394+
"""
395+
Set note.
396+
"""
397+
for item in self.session.query(Note).filter(Note.guid == obj.guid).all():
398+
self.session.delete(item)
399+
400+
note = pickle.dumps(obj)
401+
instance = Note(obj.guid, note)
402+
self.session.add(instance)
403+
404+
self.session.commit()
405+
return True
406+
407+
@logging
408+
def getNote(self, guid):
409+
"""
410+
Get note by GUID.
411+
"""
412+
note = self.session.query(Note).filter(Note.guid == guid).first()
413+
if note:
414+
return pickle.loads(note.obj)
415+
else:
416+
return None
417+
375418
@logging
376419
def setSearch(self, search_obj):
377420
"""

0 commit comments

Comments
 (0)