def add(self, anote): ''' To create a new note, simply create a new Note object and fill in attributes such as the note's title. ''' note = Types.Note() note.title = anote["title"] if (anote.has_key("attachment")) and (len(anote["attachment"]) > 0): (resource, hashHex) = _get_resource(anote["attachment"]) note.resources = [resource] ''' The content of an Evernote note is represented using Evernote Markup Language (ENML). The full ENML specification can be found in the Evernote API Overview at http://dev.evernote.com/documentation/cloud/chapters/ENML.php ''' anote_content = open(anote["content"], "r").readlines() note.content = '<?xml version="1.0" encoding="UTF-8"?>' note.content += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' # TODO: change content from plain text to html note.content += '<en-note>' + anote_content + '<br/>' if anote.has_key("attachment"): note.content += '<en-media type="image/png" hash="' + hashHex + '"/>' note.content += '</en-note>' print note.content # Finally, send the new note to Evernote using the createNote method # The new Note object that is returned will contain server-generated # attributes such as the new note's unique GUID. createdNote = self.noteStore.createNote(self.authToken, note) print "Successfully created a new note with GUID: ", createdNote.guid
def do_run(self, edit): note = Types.Note() noteStore = self.get_note_store() note.title = self.view.settings().get("$evernote_title") note.guid = self.view.settings().get("$evernote_guid") populate_note(note, self.view, self.get_notebooks()) sublime.status_message("Updating note, please wait...") def __update_note(): try: cnote = noteStore.updateNote(self.token(), note) self.view.settings().set("$evernote", True) self.view.settings().set("$evernote_guid", cnote.guid) self.view.settings().set("$evernote_title", cnote.title) sublime.status_message("Successfully updated note: guid:%s" % cnote.guid) except Errors.EDAMUserException as e: if e.errorCode == 9: self.connect(self.__update_note) else: if sublime.ok_cancel_dialog( 'Evernote complained:\n\n%s\n\nRetry?' % e.parameter): self.connect(self.__update_note) except Exception as e: sublime.error_message('Error %s' % e) __update_note()
def create_note(self): new_text = get_input() mytext = self.wrap_note_to_enml(new_text) mynote = ttypes.Note() mynote.title = self.noteName mynote.content = mytext self.noteStore.createNote(self.client.token, mynote)
def write_note(self): note = NoteType.Note() # Creates a new note note.title = "Stephanie Note" self.assistant.say("What would you like me to write down?") the_note = self.assistant.listen().decipher( ) # Listens to the input and stores it note.content = '<?xml version="1.0" encoding="UTF-8"?>' note.content += '<!DOCTYPE en-note SYSTEM ' \ '"http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>Note:<br/>' note.content += ('%s' % the_note) note.content += '</en-note>' try: created_note = self.note_store.createNote( note) # Stores the new note in Evernote except: response = (_("error.note.create")) print(response) return response if created_note: return _("note.create.success") else: response = (_("error.note.create")) print(response) return response
def create_note(self, notebook, title, content): note = Types.Note() note.title = title note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>{}</en-note>'.format(content) note.notebookGuid = notebook.guid return self.note_store.createNote(note)
def _notebook(trigger, note_store): """ :param trigger: trigger object :param note_store: note_store object :return: note object """ note = Types.Note() if trigger.notebook: # get the notebookGUID ... notebook_id = EvernoteMgr.get_notebook(note_store, trigger.notebook) # create notebookGUID if it does not exist then return its id note.notebookGuid = EvernoteMgr.set_notebook( note_store, trigger.notebook, notebook_id) if trigger.tag: # ... and get the tagGUID if a tag has been provided tag_id = EvernoteMgr.get_tag(note_store, trigger.tag) if tag_id is False: tag_id = EvernoteMgr.set_tag(note_store, trigger.tag, tag_id) # set the tag to the note if a tag has been provided note.tagGuids = tag_id logger.debug("notebook that will be used %s", trigger.notebook) return note
def inner_create_note(self, notebook_name, note_title, html, guid=None): note = Types.Note() if isinstance(note_title, unicode): note.title = note_title.encode('utf-8') else: note.title = note_title if guid: note.guid = guid note.content = '<?xml version="1.0" encoding="UTF-8"?>' note.content += '<!DOCTYPE en-note SYSTEM ' \ '"http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>' note.content += html note.content += '</en-note>' if isinstance(note.content, unicode): note.content = note.content.encode('utf-8') notebook_guid = self.get_notebook_guid(notebook_name) if not notebook_guid: log.error('In create_note, can not get a notebook named ' + notebook_name) return False note.notebookGuid = notebook_guid return note
def updateNote(self, guid, title=None, content=None, tags=None, notebook=None, resources=None): note = Types.Note() note.guid = guid if title: note.title = title if content: note.content = content if tags: note.tagNames = tags if notebook: note.notebookGuid = notebook if resources: """ TODO """ print("Updating a note's resources is not yet supported.") raise NotImplementedError() logging.debug("Update note : %s", note) self.getNoteStore().updateNote(self.authToken, note) return True
def testNote2buffer(self): # {{{ editor = EvervimEditor.getInstance() note = Types.Note() note.title = u'タイトルテスト'.encode('utf-8') note.tagNames = [u'タグ1'.encode('utf-8'), u'*タグ2'.encode('utf-8')] note.content = u"""<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>this is content 本文テスト <h3>たぐ3</h3> </en-note> """.encode('utf-8') EvervimPref.getInstance().usemarkdown = '0' # dont use markdown EvervimPref.getInstance().xmlindent = ' ' # default ts=4 xmlStrings = editor.note2buffer(note) self.assertEqual(u'タイトルテスト'.encode('utf-8'), xmlStrings[0]) self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[1]) self.assertEqual('this is content'.encode('utf-8'), xmlStrings[2]) # this is content self.assertEqual('本文テスト'.encode('utf-8'), xmlStrings[3]) # 本文テスト self.assertEqual('<h3>'.encode('utf-8'), xmlStrings[4]) # <h3> self.assertEqual(' たぐ3'.encode('utf-8'), xmlStrings[5]) # たぐ3 self.assertEqual('</h3>'.encode('utf-8'), xmlStrings[6]) # </h3> EvervimPref.getInstance().usemarkdown = '1' # dont use markdown mkdStrings = editor.note2buffer(note) self.assertEqual(u'# タイトルテスト'.encode('utf-8'), mkdStrings[0]) self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[1]) self.assertEqual('this is content'.encode('utf-8'), mkdStrings[2]) self.assertEqual('本文テスト'.encode('utf-8'), mkdStrings[3]) self.assertEqual('### たぐ3'.encode('utf-8'), mkdStrings[4])
def create_note(notebook, pdf, images, tag): '''images is a len=2 list where first are blue and then yellow highlights''' media = '<en-media type="{typ}" hash="{hash}" /><br/><br/>' highlight_choices = defaultdict(str, blue='To read later:<br/>', blue2='To read later:<br/>', yellow='To remember:<br/>') note = ttypes.Note() note.notebookGuid = notebook.guid if tag: note.tagNames = [tag] note.title = os.path.basename(pdf) note.content = '''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note><h2>Highlights:</h2>''' resources = [] for color, imgs in images.items(): note.content += highlight_choices[color] for img in imgs: resource, h = create_resource(img, typ='image/png') note.content += media.format(typ='image/png', hash=h) resources += [resource] resource, h = create_resource(pdf) resources += [resource] note.content += media.format(typ='application/pdf', hash=h) note.content += '</en-note>' note.resources = resources return note
def showiprecords(): """ 综合输出ip记录 """ namestr = 'everip' ip, wifi, wifiid, tun, device_id = iprecord() if ip is None: logstr = '无效ip,可能是没有处于联网状态' log.critical(logstr) sys.exit(1) print(f'{ip}\t{wifi}\t{wifiid}\t{tun}\t{device_id}') if not (guid := getcfpoptionvalue(namestr, device_id, 'guid')): token = getcfpoptionvalue('everwork', 'evernote', 'token') note_store = get_notestore() parentnotebook = note_store.getNotebook( '4524187f-c131-4d7d-b6cc-a1af20474a7f') evernoteapijiayi() note = ttypes.Note() note.title = f'服务器_{device_id}_ip更新记录' # note.title = "hengchu" print(note.title) note = makenote(token, note_store, note.title, notebody='', parentnotebook=parentnotebook) guid = note.guid setcfpoptionvalue(namestr, device_id, 'guid', guid)
def do_run(self, edit): note = Types.Note() noteStore = self.get_note_store() note.title = self.view.settings().get("$evernote_title") note.guid = self.view.settings().get("$evernote_guid") self.populate_note(note, self.view) self.message("Updating note, please wait...") def __update_note(): try: cnote = noteStore.updateNote(self.token(), note) self.view.settings().set("$evernote", True) self.view.settings().set("$evernote_guid", cnote.guid) self.view.settings().set("$evernote_title", cnote.title) self.message("Successfully updated note: guid:%s" % cnote.guid) self.update_status_info(cnote) except Exception as e: if sublime.ok_cancel_dialog( 'Evernote complained:\n\n%s\n\nRetry?' % explain_error(e)): self.connect(self.__update_note) __update_note()
def create_new_note(client, note_title, note_content, parentNotebook=None): noteStore = client.get_note_store() note = Types.Note() note.title = note_title note.content = generate_note_content(note_content) if parentNotebook and hasattr(parentNotebook, 'guid'): note.notebookGuid = parentNotebook.guid note = noteStore.createNote(note)
def createNote(self): newText = getInput() mytext = self.wrapNotetoHTML(newText) mynote = Types.Note() mynote.title = self.noteName mynote.content = mytext self.noteStore.createNote(self.authToken,mynote)
def delete_note(self, note): if type(self.myfile(note)) != type(Types.Note()): raise Exception('Types Error') self.noteStore.deleteNote(self.token, self.myfile(note).guid) # BUG if LOCAL_STORAGE: self.storage.delete_note(note) print_line('删除笔记 %s !' % note)
def EvernoteAddNote(notedata): # To create a new note, simply create a new Note object and fill in # attributes such as the note's title. note = Types.Note() #note.title = "Test note from EDAMTest.py" note.title = notedata["Title"] note.content = '<?xml version="1.0" encoding="UTF-8"?>' note.content += '<!DOCTYPE en-note SYSTEM ' \ '"http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>%s<br/>' % notedata["Content"] # To include an attachment such as an image in a note, first create a Resource # for the attachment. At a minimum, the Resource contains the binary attachment # data, an MD5 hash of the binary data, and the attachment MIME type. # It can also include attributes such as filename and location. for root, dirs, files in os.walk(notedata["PicPath"], False): print("Root = ", root, "dirs = ", dirs, "files = ", files) for file in files: image_path=root+"/"+file print("image_path:" + str(image_path)) with open(image_path, 'rb') as image_file: image = image_file.read() md5 = hashlib.md5() md5.update(image) hash = md5.digest() data = Types.Data() data.size = len(image) data.bodyHash = hash data.body = image resource = Types.Resource() resource.mime = 'image/jpg' resource.data = data # Now, add the new Resource to the note's list of resources note.resources = [resource] # To display the Resource as part of the note's content, include an <en-media> # tag in the note's ENML content. The en-media tag identifies the corresponding # Resource using the MD5 hash. hash_hex = binascii.hexlify(hash) hash_str = hash_hex.decode("UTF-8") # The content of an Evernote note is represented using Evernote Markup Language # (ENML). The full ENML specification can be found in the Evernote API Overview # at http://dev.evernote.com/documentation/cloud/chapters/ENML.php note.content += '<en-media type="image/jpg" hash="{}"/>'.format(hash_str) note.content += '</en-note>' # Finally, send the new note to Evernote using the createNote method # The new Note object that is returned will contain server-generated # attributes such as the new note's unique GUID. created_note = note_store.createNote(note) print("Successfully created a new note with GUID: ", created_note.guid)
def createNote(self, title, content, tags=None, notebook=None, created=None, resources=None): def make_resource(filename): try: mtype = mimetypes.guess_type(filename)[0] if mtype.split('/')[0] == "text": rmode = "r" else: rmode = "rb" with open(filename, rmode) as f: """ file exists """ resource = Types.Resource() resource.data = Types.Data() data = f.read() md5 = hashlib.md5() md5.update(data) resource.data.bodyHash = md5.hexdigest() resource.data.body = data resource.data.size = len(data) resource.mime = mtype resource.attributes = Types.ResourceAttributes() resource.attributes.fileName = os.path.basename(filename) return resource except IOError: msg = "The file '%s' does not exist." % filename out.failureMessage(msg) raise IOError(msg) note = Types.Note() note.title = title note.content = content note.created = created if tags: note.tagNames = tags if notebook: note.notebookGuid = notebook if resources: """ make EverNote API resources """ note.resources = map(make_resource, resources) """ add to content """ resource_nodes = "" for resource in note.resources: resource_nodes += '<en-media type="%s" hash="%s" />' % (resource.mime, resource.data.bodyHash) note.content = note.content.replace("</en-note>", resource_nodes + "</en-note>") logging.debug("New note : %s", note) return self.getNoteStore().createNote(self.authToken, note)
def createNote(self, title, content, tags=None, created=None, notebook=None, resources=None, reminder=None): note = Types.Note() note.title = title try: note.content = content.encode('utf-8') except UnicodeDecodeError: note.content = content if tags: note.tagNames = tags note.created = created if notebook: note.notebookGuid = notebook if resources: """ make EverNote API resources """ note.resources = list(map(make_resource, resources)) """ add to content """ resource_nodes = "" for resource in note.resources: resource_nodes += '<en-media type="%s" hash="%s" />' % ( resource.mime, resource.data.bodyHash) note.content = note.content.replace("</en-note>", resource_nodes + "</en-note>") # Allow creating a completed reminder (for task tracking purposes), # skip reminder creation steps if we have a DELETE if reminder and reminder != config.REMINDER_DELETE: now = int(round(time.time() * 1000)) note.attributes = Types.NoteAttributes() if reminder == config.REMINDER_NONE: note.attributes.reminderOrder = now elif reminder == config.REMINDER_DONE: note.attributes.reminderOrder = now note.attributes.reminderDoneTime = now else: # we have an actual reminder time stamp if reminder > now: # future reminder only note.attributes.reminderOrder = now note.attributes.reminderTime = reminder else: out.failureMessage( "Sorry, reminder must be in the future.") tools.exitErr() logging.debug("New note : %s", note) return self.getNoteStore().createNote(self.authToken, note)
def newNote(self, notebook): note = Types.Note() if notebook is not False: note.notebookGuid = notebook.guid else: note.notebookGuid = self.defaultNotebook.guid return note
def delete_note(self, noteFullPath): if self.get(noteFullPath) is None: return False if type(self.get(noteFullPath)) != type(Types.Note()): raise Exception('Types Error') if self.isSpecialToken: self.noteStore.expungeNote(self.token, self.get(noteFullPath).guid) else: self.noteStore.deleteNote(self.token, self.get(noteFullPath).guid) self.storage.delete_note(noteFullPath) return True
def create_note(note_store, notebook_guid, title, content=None): note = Types.Note() note.title = title note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>' note.content += content or '' note.notebookGuid = notebook_guid note.content += '</en-note>' note_store.createNote(note)
def _create_evernote_note(self, data): # Create the new note note = Types.Note() note.title = data['title'] note.notebookGuid = self.notebook.guid note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' \ '<en-note>%s<br/>' \ '</en-note>'%(data['content']) return note
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))
def create_note(auth_token, note_store, level, note_title, resources=None, headings=None, widths=None, tag=None, intro=None, ending=None): """ Create note in Evernote. :param auth_token: development token. :param note_store: note store object. :param level: (int) time frame number. :param note_title: (str) title for note. :param resources: (list) resources (images) add into note. :param headings: (list) headers for images. :param widths: (list) width of image. :param tag: (str) a div contain list of tags for future search. :param intro: (str) Some text add before all images. :param ending: (str) Other title add after all images. :return: note. """ # Create note object our_note = ever_types.Note() our_note.title = note_title # Build body of note note_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" note_body += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" note_body += "<en-note>" if tag is not None: note_body += tag if intro is not None: note_body = note_body + intro + '<br /><br />' if resources: # Add Resource objects to note body our_note.resources = resources for resource, heading, width in zip(resources, headings, widths): heading = headify(heading) note_body += heading resource = resoursify(resource, width) note_body += resource if ending is None: ending = "Have a nice {0}!".format(LEVEL2STR[level][:-1]) note_body += headify(ending) note_body += "<br /></en-note>" our_note.content = note_body if level == 0: our_note.notebookGuid = DIARY else: our_note.notebookGuid = REVIEW note = note_store.createNote(auth_token, our_note) return note
def test_update_note(self, sdk): content = '<?xml version="1.0" encoding="UTF-8"?>'\ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'\ '<en-note><br />'\ '<div>test text</div>'\ '<p>Test</p><br />'\ '</en-note>' note = Types.Note(guid="123", title="One big note", content=content) note.notebookGuid = "notebook" self.note_store().getNote = mock.Mock(return_value=note) self.note_store().createNote = mock.Mock(return_value=Types.Note(guid="new")) self.note_store().updateNote = mock.Mock(return_value="updated") sdk().get_note_store = self.note_store api = EvernoteApi("access_token") api.get_note_link = mock.Mock(return_value="http://evernote.com/123") tmp_filename = None with tempfile.NamedTemporaryFile(mode="r+", suffix=".txt", dir="/tmp") as f: f.write("Hello") tmp_filename = basename(f.name) result = api.update_note("123", text="Merry Christmas", title="Santa Claus", html="<p>New Year</p>", files=[{"path": f.name, "name": tmp_filename}]) self.assertEqual(result, "updated") self.note_store().createNote.assert_called_once() call_args = self.note_store().createNote.call_args[0] self.assertEqual(call_args[0].title, "Santa Claus") self.note_store().updateNote.assert_called_once() call_args = self.note_store().updateNote.call_args[0] self.assertEqual(len(call_args), 1) self.assertEqual(call_args[0].title, "One big note") self.assertEqual(call_args[0].notebookGuid, "notebook") self.assertEqual( call_args[0].content, '<?xml version="1.0" encoding="UTF-8"?>' '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' '<en-note><br />' '<div>test text</div>' '<p>Test</p><br />' '<br /><div>Merry Christmas</div><p>New Year</p><br />' f'<a href="http://evernote.com/123">{tmp_filename}</a>' '</en-note>')
def makeNote(cls, title, content, in_notebook_guid=None, resources=None, tags=[], created=None, updated=None): note = Types.Note(title=title, tagNames=tags) note.content = cls.noteTemplate().safe_substitute({'content': content}) note.resources = resources if in_notebook_guid: note.notebookGuid = in_notebook_guid note.created = created note.updated = updated return note
def create_note(self, note_text, title=None): if title==None: title=str(datetime.datetime.now()) note = Types.Note() note.title = title note.content = '<?xml version="1.0" encoding="UTF-8"?>' note.content += '<!DOCTYPE en-note SYSTEM ' \ '"http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note>' + note_text + '</en-note>' created_note = self.note_store.createNote(note)
def create_note(self, title, content, notebook = None): note = Types.Note() note.title = title note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' note.content += content #'<en-note>Hello, world!</en-note>' if notebook: note.notebookGuid = self.myfile(notebook).guid note = self.noteStore.createNote(note) if LOCAL_STORAGE: self.storage.create_note(note, notebook) print_line('Created note: %s successfully' %title)
def create(self, title, content, notebook=None): note = Types.Note() note.title = title note.content = content if notebook: note.notebookGuid = notebook.guid created_note = self.get_notestore().createNote(self.authToken, note) print 'Successfully created a note with GUID: ', created_note.guid
def create_note(self, title): note = Types.Note() note.title = title note.content = '<?xml version="1.0" encoding="UTF-8"?>\ <!DOCTYPE en-note SYSTEM \ "http://xml.evernote.com/pub/enml2.dtd">' note.content += '<en-note></en-note>' note = self.noteStore.createNote(note) return bool(note)