Permalink
Browse files

added control tags

  • Loading branch information...
stepler committed Jul 8, 2012
1 parent 03068d4 commit b8756e835f0d1ea71d0d4df181345a061396e455
Showing with 169 additions and 50 deletions.
  1. +30 −0 argparser.py
  2. +5 −3 config.py
  3. +130 −45 geeknote.py
  4. +4 −2 out.py
View
@@ -101,8 +101,37 @@
"--title": {"help": "Set the new name of notebook."},
}
},
+
+ # Tags
+ "tag-list": {
+ "help": "Show the list of existing tags in your Evernote.",
+ },
+ "tag-create": {
+ "help": "Create new tag.",
+ "arguments": {
+ "--title": {"help": "Set the title of new tag."},
+ }
+ },
+ "tag-edit": {
+ "help": "Edit/rename tag.",
+ "firstArg": "--tag",
+ "arguments": {
+ "--tag": {"help": "The name of a tag to rename."},
+ "--title": {"help": "Set the new name of tag."},
+ }
+ },
}
"""
+ "tag-remove": {
+ "help": "Remove tag.",
+ "firstArg": "--tag",
+ "arguments": {
+ "--tag": {"help": "The name of a tag to remove."},
+ },
+ "flags": {
+ "--force": {"help": "Don't ask about removing.", "value": True, "default": False},
+ }
+ },
"notebook-remove": {
"help": "Remove notebook.",
"firstArg": "--notebook",
@@ -114,6 +143,7 @@
}
},
"""
+
class argparser(object):
COMMANDS = COMMANDS_DICT
View
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
-import os, sys
-
-# Evernote config
# !!! DO NOT EDIT !!! >>>
USER_BASE_URL = "www.evernote.com"
USER_STORE_URI = "https://www.evernote.com/edam/user"
@@ -15,6 +12,11 @@
CONSUMER_SECRET_SANDBOX = "ed0fcc0c97c032a5"
# !!! DO NOT EDIT !!! <<<
+import os, sys
+# Evernote config
+
+VERSION = 0.1
+
IS_IN_TERMINAL = sys.stdin.isatty()
IS_OUT_TERMINAL = sys.stdout.isatty()
View
@@ -74,9 +74,13 @@ def EdamException(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
- except Errors.EDAMUserException as e:
+ except Exception, e:
logging.error("Error: %s : %s", func.__name__, str(e))
+ if not hasattr(e, 'errorCode'):
+ out.failureMessage("Sorry, operation has failed!!!.")
+ tools.exit()
+
errorCode = int(e.errorCode)
# auth-token error, re-auth
@@ -90,9 +94,10 @@ def wrapper(*args, **kwargs):
out.failureMessage("Sorry, you do not have permissions to do this operation.")
else:
- out.failureMessage("Sorry, operation has failed.")
+ return False
tools.exit()
+
return wrapper
def getStorage(self):
@@ -193,12 +198,8 @@ def createNote(self, title, content, tags=None, notebook=None):
logging.debug("New note : %s", note)
- try:
- self.getNoteStore().createNote(self.authToken, note)
- return True
- except Exception, e:
- logging.error("Error: %s", str(e))
- return False
+ self.getNoteStore().createNote(self.authToken, note)
+ return True
@EdamException
def updateNote(self, guid, title=None, content=None, tags=None, notebook=None):
@@ -218,22 +219,15 @@ def updateNote(self, guid, title=None, content=None, tags=None, notebook=None):
logging.debug("Update note : %s", note)
- try:
- self.getNoteStore().updateNote(self.authToken, note)
- return True
- except Exception, e:
- logging.error("Error: %s", str(e))
- return False
+ self.getNoteStore().updateNote(self.authToken, note)
+ return True
@EdamException
- def deleteNote(self, guid):
+ def removeNote(self, guid):
logging.debug("Delete note with guid: %s", guid)
- try:
- self.getNoteStore().deleteNote(self.authToken, guid)
- return True
- except Exception, e:
- logging.error("Error: %s", str(e))
- return False
+
+ self.getNoteStore().deleteNote(self.authToken, guid)
+ return True
"""
WORK WITH NOTEBOOKS
@@ -249,12 +243,8 @@ def createNotebook(self, name):
logging.debug("New notebook : %s", notebook)
- try:
- result = self.getNoteStore().createNotebook(self.authToken, notebook)
- return result
- except Exception, e:
- logging.error("Error: %s", str(e))
- return False
+ result = self.getNoteStore().createNotebook(self.authToken, notebook)
+ return result
@EdamException
def updateNotebook(self, guid, name):
@@ -264,23 +254,50 @@ def updateNotebook(self, guid, name):
logging.debug("Update notebook : %s", notebook)
- try:
- self.getNoteStore().updateNotebook(self.authToken, notebook)
- return True
- except Exception, e:
- logging.error("Error: %s", str(e))
- return False
+ self.getNoteStore().updateNotebook(self.authToken, notebook)
+ return True
@EdamException
- def deleteNotebook(self, guid):
+ def removeNotebook(self, guid):
logging.debug("Delete notebook : %s", guid)
- try:
- self.getNoteStore().expungeNotebook(self.authToken, guid)
- return True
- except Exception, e:
- logging.error("Error: %s", str(e))
- return False
+ self.getNoteStore().expungeNotebook(self.authToken, guid)
+ return True
+
+ """
+ WORK WITH TAGS
+ """
+ @EdamException
+ def findTags(self):
+ return self.getNoteStore().listTags(self.authToken)
+
+ @EdamException
+ def createTag(self, name):
+ tag = Types.Tag()
+ tag.name = name
+
+ logging.debug("New tag : %s", tag)
+
+ result = self.getNoteStore().createTag(self.authToken, tag)
+ return result
+
+ @EdamException
+ def updateTag(self, guid, name):
+ tag = Types.Tag()
+ tag.name = name
+ tag.guid = guid
+
+ logging.debug("Update tag : %s", tag)
+
+ self.getNoteStore().updateTag(self.authToken, tag)
+ return True
+
+ @EdamException
+ def removeTag(self, guid):
+ logging.debug("Delete tag : %s", guid)
+
+ self.getNoteStore().expungeTag(self.authToken, guid)
+ return True
class GeekNoteConnector(object):
evernote = None
@@ -360,6 +377,64 @@ def settings(self, editor=None):
self.getStorage().setUserprop('editor', editor)
out.successMessage("Changes have been saved.")
+class Tags(GeekNoteConnector):
+ """ Work with auth Notebooks """
+
+ def list(self):
+ result = self.getEvernote().findTags()
+ out.printList(result)
+
+ def create(self, title):
+ self.connectToEvertone()
+ out.preloader.setMessage("Creating tag...")
+ result = self.getEvernote().createTag(name=title)
+
+ if result:
+ out.successMessage("Tag has been successfully created.")
+ else:
+ out.failureMessage("Error while the process of creating the tag.")
+ return tools.exit()
+
+ return result
+
+ def edit(self, tag, title):
+ tag = self._searchTag(tag)
+
+ out.preloader.setMessage("Updating tag...")
+ result = self.getEvernote().updateTag(guid=tag.guid, name=title)
+
+ if result:
+ out.successMessage("Tag has been successfully updated.")
+ else:
+ out.failureMessage("Error while the updating the tag.")
+ return tools.exit()
+
+ def remove(self, tag, force=None):
+ tag = self._searchTag(tag)
+
+ if not force and not out.confirm('Are you sure you want to delete this tag: "%s"?' % tag.name):
+ return tools.exit()
+
+ out.preloader.setMessage("Deleting tag...")
+ result = self.getEvernote().removeTag(guid=tag.guid)
+
+ if result:
+ out.successMessage("Tag has been successfully removed.")
+ else:
+ out.failureMessage("Error while removing the tag.")
+
+ def _searchTag(self, tag):
+ result = self.getEvernote().findTags()
+ tag = [item for item in result if item.name == tag]
+
+ if tag:
+ tag = tag[0]
+ else:
+ tag = out.SelectSearchResult(result)
+
+ logging.debug("Selected tag: %s" % str(tag))
+ return tag
+
class Notebooks(GeekNoteConnector):
""" Work with auth Notebooks """
@@ -381,7 +456,6 @@ def create(self, title):
return result
def edit(self, notebook, title):
-
notebook = self._searchNotebook(notebook)
out.preloader.setMessage("Updating notebook...")
@@ -394,14 +468,13 @@ def edit(self, notebook, title):
return tools.exit()
def remove(self, notebook, force=None):
-
notebook = self._searchNotebook(notebook)
if not force and not out.confirm('Are you sure you want to delete this notebook: "%s"?' % notebook.name):
return tools.exit()
out.preloader.setMessage("Deleting notebook...")
- result = self.getEvernote().deleteNotebook(guid=notebook.guid)
+ result = self.getEvernote().removeNotebook(guid=notebook.guid)
if result:
out.successMessage("Notebook has been successfully removed.")
@@ -432,7 +505,6 @@ def getNoteGUID(self, notebook):
else:
return None
-
class Notes(GeekNoteConnector):
""" Work with Notes """
@@ -480,7 +552,7 @@ def remove(self, note, force=None):
return tools.exit()
out.preloader.setMessage("Deleting note...")
- result = self.getEvernote().deleteNote(note.guid)
+ result = self.getEvernote().removeNote(note.guid)
if result:
out.successMessage("Note has been successful deleted.")
@@ -735,6 +807,19 @@ def main(args=None):
if COMMAND == 'notebook-remove':
Notebooks().remove(**ARGS)
+ # Tags
+ if COMMAND == 'tag-list':
+ Tags().list(**ARGS)
+
+ if COMMAND == 'tag-create':
+ Tags().create(**ARGS)
+
+ if COMMAND == 'tag-edit':
+ Tags().edit(**ARGS)
+
+ if COMMAND == 'tag-remove':
+ Tags().remove(**ARGS)
+
except (KeyboardInterrupt, SystemExit, tools.ExitException):
pass
View
6 out.py
@@ -82,7 +82,6 @@ def draw():
printLine("%s : %s" % (preloader.progress[preloader.counter % len(preloader.progress)], preloader.message), "")
time.sleep(0.3)
- raise
except:
pass
@@ -234,4 +233,7 @@ def printLine(line, endLine="\n"):
pass
def printAbout():
- printLine('About geeknote')
+ printLine('Version: %s' % str(config.VERSION))
+ printLine('Geeknote - a command line client for Evernote.')
+ printLine('Use geeknote --help to read documentation.')
+ printLine('And visit www.geeknote.me to check for updates.')

0 comments on commit b8756e8

Please sign in to comment.