From b43e6be1ef51c7764556e2e9537dccfe113ffc4c Mon Sep 17 00:00:00 2001 From: Bruno Date: Wed, 15 Nov 2017 12:20:06 +0100 Subject: [PATCH 1/2] try to ensure ascii for tags --- anknotes/__main__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/anknotes/__main__.py b/anknotes/__main__.py index bf617a9..07eec92 100644 --- a/anknotes/__main__.py +++ b/anknotes/__main__.py @@ -79,6 +79,7 @@ def update_note(self, fields, tags=list()): return note.id def add_note(self, deck_name, model_name, fields, tags=list()): + tags = ensure_ascii_tags(tags) note = self.create_note(deck_name, model_name, fields, tags) if note is not None: collection = self.collection() @@ -330,6 +331,16 @@ def decode(key, enc): return "".join(dec) +def ensure_ascii_tags(tags): + new_tags = [] + for tag in tags[:]: + if not isinstance(tag, str): + new_tags.append(tag.encode('ascii', 'ignore')) + else: + new_tags.append(tag) + return new_tags + + def main(): controller = Controller() controller.proceed() From 5798daa34b294391ade69f7f04741d4b36e96efc Mon Sep 17 00:00:00 2001 From: Bruno Date: Thu, 16 Nov 2017 07:55:39 +0100 Subject: [PATCH 2/2] try to catch wrong token errors ; UNTESTED yet --- anknotes/__main__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/anknotes/__main__.py b/anknotes/__main__.py index 07eec92..47577f2 100644 --- a/anknotes/__main__.py +++ b/anknotes/__main__.py @@ -19,6 +19,7 @@ # Note: This class was adapted from the Real-Time_Import_for_use_with_the_Rikaisama_Firefox_Extension plug-in # by cb4960@gmail.com # .. itself adapted from Yomichan plugin by Alex Yatskov. +from anknotes.evernote.edam.error.ttypes import EDAMUserException PATH = os.path.dirname(os.path.abspath(__file__)) EVERNOTE_MODEL = 'evernote_note' @@ -203,7 +204,12 @@ def __init__(self): auth_token_encoded = mw.col.conf.get(SETTING_TOKEN, False) auth_token = decode(secret_key, auth_token_encoded) self.token = auth_token - self.client = EvernoteClient(token=auth_token, sandbox=False) + try: + self.client = EvernoteClient(token=auth_token, sandbox=False) + except EDAMSystemException, e: + if e.errorCode == 2: + show_tooltip("Problem with your token, did you enter the good password ?") + raise self.noteStore = self.client.get_note_store() def find_tag_guid(self, tag): @@ -243,7 +249,7 @@ def get_note_information(self, note_guid): except EDAMSystemException, e: if e.errorCode == EDAMErrorCode.RATE_LIMIT_REACHED: m, s = divmod(e.rateLimitDuration, 60) - showInfo("Rate limit has been reached. We will save the notes downloaded thus far.\r\n" + show_tooltip("Rate limit has been reached. We will save the notes downloaded thus far.\r\n" "Please retry your request in {} min".format("%d:%02d" % (m, s))) return None raise