Exemplo n.º 1
0
 def create_notebook(self, title):
     notebook = Types.Notebook()
     notebook.name = title
     notebook = self.noteStore.createNotebook(notebook)
     if LOCAL_STORAGE:
         self.storage.create_notebook(notebook)
     print_line('成功创建笔记本: %s!' % title)
Exemplo n.º 2
0
 def create_notebook(self, title):
     if self.get(title): return False
     notebook = Types.Notebook()
     notebook.name = title
     notebook = self.noteStore.createNotebook(notebook)
     self.storage.create_notebook(notebook)
     return True
Exemplo n.º 3
0
 def delete_notebook(self, notebook):
     if self.get(notebook) or not self.isSpecialToken: return False
     if type(self.get(notebook)) != type(Types.Notebook()):
         raise Exception('Types Error')
     self.noteStore.expungeNotebook(self.token, self.get(notebook).guid)
     self.storage.delete_notebook(notebook)
     return True
Exemplo n.º 4
0
    def test_check_notebook(self):
        with patch("pypdfocr.pypdfocr_filer_evernote.EvernoteClient"
                   ) as mock_evernote_client:
            p = P.PyFilerEvernote("TOKEN")
            p._check_and_make_notebook("new_notebook")
            # Let's assert that we tried to create a new notebook
            mock_client = mock_evernote_client.return_value
            assert (mock_client.get_note_store.called)
            create_func = mock_client.get_note_store.return_value.createNotebook
            update_func = mock_client.get_note_store.return_value.updateNotebook
            assert (create_func.called)
            assert (not update_func.called)
            notebook = create_func.call_args[0][0]
            assert (notebook.name == 'new_notebook')

            # Now, let's setup a value for the notebooks, so we test the code for
            # a "pre-exisiting" notebook
            test_notebook = Types.Notebook()
            test_notebook.name = "new_notebook"
            mock_client.get_note_store.return_value.listNotebooks.return_value = [
                test_notebook
            ]
            p._check_and_make_notebook("new_notebook")

            # Now check that the code to update a notebook stack is correct
            test_notebook.stack = "new_stack"
            update_func = mock_client.get_note_store.return_value.updateNotebook
            p.set_target_folder("Boogie")
            p._check_and_make_notebook("new_notebook")
            # Check that the update call was called with correct arguments
            assert (update_func.called)
            notebook = update_func.call_args[0][0]
            assert (notebook.stack == 'Boogie')
Exemplo n.º 5
0
 def _check_and_make_notebook(self, notebook_name):
     """
         Weird.
         :returns notebook: New or existing notebook object
         :rtype Types.Notebook:
     """
     # Get the noteStore
     #note_store = self.client.get_note_store()
     #notebooks = note_store.listNotebooks()
     #notebooks = {n.name:n for n in notebooks}
     notebooks = self._get_notebooks()
     if notebook_name in notebooks:
         notebook = notebooks[notebook_name]
         if notebook.stack != self.target_folder:
             notebook.stack = self.target_folder
             self._update_notebook(notebook)
         return notebook
     else:
         # Need to create a new notebook
         notebook = Types.Notebook()
         notebook.name = notebook_name
         notebook.stack = self.target_folder
         notebook = self._create_notebook(notebook)
         #notebook = note_store.createNotebook(notebook)
         return notebook
 def delete_notebook(self, notebook):
     if SPECIAL_DEV_TOKEN:
         if type(self.myfile(notebook)) != type(Types.Notebook()): raise Exception('Types Error')
         self.noteStore.expungeNotebook(self.token, self.myfile(notebook).guid)
         # BUG
         if LOCAL_STORAGE: self.storage.delete_notebook(notebook)
         print_line('Deleted %s successfully'%notebook)
Exemplo n.º 7
0
    def createNotebook(self, name):
        notebook = Types.Notebook()
        notebook.name = name

        logging.debug("New notebook : %s", notebook)

        result = self.getNoteStore().createNotebook(self.authToken, notebook)
        return result
Exemplo n.º 8
0
 def test_pull_new_notebook(self):
     """Test pull new notebook"""
     notebook_name = 'name'
     self.note_store.listNotebooks.return_value = [
         ttypes.Notebook(name=notebook_name),
     ]
     self.sync.pull()
     notebook = self.session.query(models.Notebook).one()
     self.assertEqual(notebook.name, notebook_name)
Exemplo n.º 9
0
def create_note_from_highlight(authToken,
                               image_files,
                               note_content,
                               ocr=False,
                               notetitle=''):
    from time import gmtime, strftime

    if notetitle == '':
        curr_time = strftime("%Y-%m-%d", gmtime())
        notetitle = "digilight {curr_time}".format(curr_time=curr_time)

    if ocr:
        all_texts = []
        for image_file in image_files:
            json_data, text = google_ocr_img(image_file)
            all_texts.append(text)

        note_content = "\n---------------------\n".join(all_texts)
    # json_data=open("jsons/api_result.json").read()

    # data = json.loads(json_data)
    # all_texts = get_all_text(data)

    client = get_evernote_client(authToken)
    userStore = client.get_user_store()
    user = userStore.getUser()

    noteStore = client.get_note_store()
    notebooks = noteStore.listNotebooks()
    found = False
    for n in notebooks:
        if n.name == 'Digilights':
            parentNotebook = n
            found = True

    if not found:
        ourNotebook = Types.Notebook()
        ourNotebook.name = "Digilights"
        parentNotebook = noteStore.createNotebook(ourNotebook)

    try:
        print "FILES TO RESOURCE:", str(image_files)
        resources = create_en_resource(image_files)
    except Exception as e:
        return "ERROR: Couldnt make evernote resource." + str(e), note_content
    try:
        note = makeNote(authToken,
                        noteStore,
                        notetitle,
                        note_content,
                        parentNotebook=parentNotebook,
                        resources=resources)
    except Exception as e:
        return "ERROR: Couldnt make evernote." + str(e), note_content

    msg = note.title + " created in " + parentNotebook.name + "!"
    return msg, note_content
Exemplo n.º 10
0
    def updateNotebook(self, guid, name):
        notebook = Types.Notebook()
        notebook.name = name
        notebook.guid = guid

        logging.debug("Update notebook : %s", notebook)

        self.getNoteStore().updateNotebook(self.authToken, notebook)
        return True
Exemplo n.º 11
0
def GeeknoteCreateNotebook(name):
    notebook = Types.Notebook()
    notebook.name = name.strip('"\'')
    try:
        notebook = GeeknoteCreateNewNotebook(notebook)
    except:
        vim.command('echoerr "Failed to create notebook."')

    explorer.addNotebook(notebook)
Exemplo n.º 12
0
 def addNotebook(self, notebookname):
     '''
     adds a Notebook to the noteStore if needed(to store all Rednotebook entries)
     '''
     notebook = Types.Notebook()
     notebook.name = notebookname
     notebook = self.noteStore.createNotebook(notebook)
     logger.info('added notebook:%s, with guid:%s' %
                 (notebookname, str(notebook.guid)))
     return notebook.guid
Exemplo n.º 13
0
def sync_to_evernotes(path):
    """将cmdmarkdown的文件更新到evernote中去"""
    evernotebooks = {i.name: i for i in note_store.listNotebooks()}
    for notebook_name in os.listdir(path):
        if notebook_name in evernotebooks:
            notebook = evernotebooks[notebook_name]
        else:
            notebook = Types.Notebook(name=notebook_name)
            note_store.createNotebook(notebook)
        sync_evernotes(notebook, os.path.join(path, notebook_name))
Exemplo n.º 14
0
def set_notebook(note_store, my_notebook, notebook_id):
    """
        create a notebook
    """
    if notebook_id == 0:
        new_notebook = Types.Notebook()
        new_notebook.name = my_notebook
        new_notebook.defaultNotebook = False
        notebook_id = note_store.createNotebook(new_notebook).guid
    return notebook_id
Exemplo n.º 15
0
def set_current_notebook_name(name):
    load_config()
    if name not in [n.name for n in get_notebooks()]:
        if not ask_yn("Notebook '%s' doesn't exist. Create it?" % name):
            print("Aborted.")
            sys.exit(1)
        notebook = Types.Notebook()
        notebook.name = name
        notebook = get_note_store().createNotebook(notebook)
    config['cur_notebook'] = name
    save_config()
Exemplo n.º 16
0
 def create_notebook(self, space):
     existing_notebooks = [
         notebook for notebook in self.notebooks if space == notebook.name
     ]
     if len(existing_notebooks):
         self.set_already_createds_for_notebook(existing_notebooks[0].guid)
         return existing_notebooks[0].guid, False
     notebook = Types.Notebook()
     notebook.name = space
     notebook = self.note_store.createNotebook(notebook)
     return notebook.guid, True
Exemplo n.º 17
0
    def set_notebook(self, trigger, notebook_id):
        """
            create a notebook
        """
        if notebook_id == 0:
            new_notebook = Types.Notebook()
            new_notebook.name = trigger.notebook
            new_notebook.defaultNotebook = False
            notebook_id = self.note_store.createNotebook(new_notebook).guid

        return notebook_id
Exemplo n.º 18
0
 def create(self, notebook_name, stack=None):
     if self.get(notebook_name, None):
         raise NoteBookAlreadyExist("%s notebook already exist" %
                                    (notebook_name))
     else:
         notebook = Types.Notebook()
         notebook.name = notebook_name
         if stack:
             notebook.stack = stack
         notebook = self._create_notebook(notebook)
         return notebook
Exemplo n.º 19
0
def create_note_book(client, bookname):
    noteStore = client.get_note_store()
    notebook = Types.Notebook()
    notebook.name = bookname
    notebook = noteStore.createNotebook(notebook)
    print notebook.guid

    if len(notebook.guid) > 0:
        return True
    else:
        return False
Exemplo n.º 20
0
 def move_note(self, noteFullPath, _to):
     if self.get(noteFullPath) is None: return False
     if type(self.get(noteFullPath)) != type(Types.Note()) or type(self.get(_to)) != type(
         Types.Notebook()): raise Exception('Type Error')
     self.noteStore.copyNote(self.token, self.get(noteFullPath).guid, self.get(_to).guid)
     if self.isSpecialToken:
         self.noteStore.expungeNote(self.token, self.get(noteFullPath).guid)
     else:
         self.noteStore.deleteNote(self.token, self.get(noteFullPath).guid)
     self.storage.move_note(noteFullPath, _to)
     return True
Exemplo n.º 21
0
    def create_notebook(self, name):
        """Create a notebook.

        :param name: The name of the notebook to create.
        :return: The created notebook.

        """
        notebook = ttypes.Notebook()
        notebook.name = name

        return self.note_store.createNotebook(notebook)
Exemplo n.º 22
0
def createAllNotebooks(noteStore, notebooksList):
    for notebook in notebooksList:
        try:
            newNotebook = Types.Notebook()
            newNotebook.name = notebook.name
            newNotebook = noteStore.createNotebook(newNotebook)
        except Exception as e:
            pass
        else:
            pass
        finally:
            pass
Exemplo n.º 23
0
 def create_notebook(self, noteFullPath):
     if self.get(noteFullPath): return False
     notebook = Types.Notebook()
     notebook.name = noteFullPath
     try:
         notebook = self.noteStore.createNotebook(notebook)
     except EDAMUserException, e:
         if e.errorCode == 10 and e.parameter == 'Notebook.name':
             self.storage.update(self.token, self.noteStore)
             return True
         else:
             raise e
Exemplo n.º 24
0
 def test_pull_not_updated_notebook(self):
     """Test pull not updated notebook"""
     notebook = factories.NotebookFactory.create(service_updated=2, )
     notebook_name = 'name*'
     self.note_store.listNotebooks.return_value = [
         ttypes.Notebook(
             name=notebook_name,
             guid=notebook.guid,
             serviceUpdated=1,
         )
     ]
     self.sync.pull()
     self.assertNotEqual(notebook.name, notebook_name)
Exemplo n.º 25
0
    def createNotebook(self, name):
        try:
            noteStore = self._getNoteStoreClient()
            notebook = Types.Notebook()
            notebook.name = name
            notebooks = noteStore.createNotebook(self.token, notebook)
        except Exception as e:
            LOG(explain_error(e))
            LOG(e)
            track = traceback.format_exc()
            print(track)

            return None
Exemplo n.º 26
0
 def create_notebook(self, notebook_name):
     log.debug('Start to create notebook ' + notebook_name)
     notebook = Types.Notebook()
     if isinstance(notebook_name, unicode):
         notebook.name = notebook_name.encode('utf-8')
     else:
         notebook.name = notebook_name
     notebook.defaultNotebook = False
     created_notebook = self.note_store.createNotebook(notebook)
     log.debug('Create notebook succeed')
     self.notebook_names[created_notebook.guid] = notebook_name
     self.notebook_guids.append(created_notebook.guid)
     self.notes[created_notebook.guid] = []
Exemplo n.º 27
0
 def createNotebook(self, notebookName):
     notebookDict= self.getNotebook()
     if notebookName in notebookDict.keys():
         guid = notebookDict[notebookName]
     else:
         try:
             notebook = Types.Notebook()
             notebook.name = notebookName.encode('utf-8')
             notebook = self.noteStore.createNotebook(notebook)
             guid = notebook.guid
         except Exception, e:
             guid = None
             print(e.message)
Exemplo n.º 28
0
 def move_note(self, note, _to):
     if type(self.myfile(note)) != type(Types.Note()) or type(
             self.myfile(_to)) != type(Types.Notebook()):
         raise Exception('Type Error')
     self.noteStore.copyNote(self.token,
                             self.myfile(note).guid,
                             self.myfile(_to).guid)
     if SPECIAL_DEV_TOKEN:
         self.noteStore.expungeNote(self.token, self.myfile(note).guid)
     else:
         self.noteStore.deleteNote(self.token, self.myfile(note).guid)
     if LOCAL_STORAGE:
         self.storage.move_note(note, _to)
     print_line('Move %s to %s successfully' % (note, _to))
Exemplo n.º 29
0
 def _check_and_make_notebook(self, notebook_name, stack=None):
     notebooks = self._get_notebooks()
     if notebook_name in notebooks:
         # Existing notebook, so just update the stack if needed
         notebook = notebooks[notebook_name]
         if stack:
             notebook.stack = stack
             self._update_notebook(notebook)
         return notebook
     else:
         # Need to create a new notebook
         notebook = Types.Notebook()
         notebook.name = notebook_name
         if stack:
             notebook.stack = stack
         notebook = self._create_notebook(notebook)
         return notebook
Exemplo n.º 30
0
def create_notebook(name=None):
    """Create a new notebook with given `name`.

    Parameters
    ----------
    name : str
        Indicating the name of the notebook to be created

    Returns
    -------
    evernote.edam.type.ttypes.Notebook

    """
    assert name is not None, 'Notebook name is not specified.'
    notebook = ttypes.Notebook()
    notebook.name = name
    return get_note_store().createNotebook(notebook)