def create_note(entry): """ ブックマーク情報からEvernoteのNoteを作成 """ client = EvernoteClient(token=global_config['evernote']['token'], sandbox=False) note_store = client.get_note_store() note = Types.Note() note.title = entry['title'] note.title = note.title.replace(unichr(int('2028', 16)), ' ') note.title = note.title.replace(unichr(int('2029', 16)), ' ') note.title = note.title.encode('utf-8') content = ( u'<?xml version="1.0" encoding="UTF-8"?>' u'<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">') content += u'<en-note>' if entry['summary']: content += u'%s<hr />' % entry['summary'] content += to_enml(entry['content'], url=entry['url']) content += u'</en-note>' soup = BeautifulSoup(content) note.content = str(soup) attrs = Types.NoteAttributes(sourceURL=entry['url']) note.attributes = attrs note.tagNames = [e.encode('utf-8') for e in entry['tags']] # 時間がミリ秒単位になるので1000を乗算する note.created = entry['created'] * 1000 note = img_to_resource(note) note_store.createNote(note) return note
def _create_remote_note(self, note_title, note_guid): """Create remote note""" remote_note = ttypes.Note( title=note_title, guid=note_guid, content='<en-note></en-note>', notebookGuid=self.notebook.guid, attributes=ttypes.NoteAttributes(), updated=1, resources=[ ttypes.Resource( guid='file', mime='text', attributes=ttypes.ResourceAttributes(fileName='file', ), data=ttypes.Data( body='', bodyHash='', ), ) ], ) search_result = MagicMock() search_result.totalNotes = 1 search_result.startIndex = 0 search_result.notes = [remote_note] self.note_store.findNotes.return_value = search_result self.note_store.getNote.return_value = remote_note return remote_note
def make_second_note(url_l): dev_token = "x" client = EvernoteClient(token=dev_token, sandbox=False) note_store = client.get_note_store() message = '' for i in url_l: message += '<br>' + i + '</br>' #message='<br>'+url+'</br>' note = Types.Note() note.title = "Backlinks(%s)" % (time.strftime("%d/%m/%Y")) note.content = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note><br>Insert Backlinks for the following articles:</br> <br></br> %s</en-note> """ % (message) now = int(round(time.time() * 1000)) then = now + 864000000 # ten days after now # init NoteAttributes instance note.attributes = Types.NoteAttributes() note.attributes.reminderOrder = now note.attributes.reminderTime = then try: createdNote = note_store.createNote(note) except Exception, e: print type(e) print e raise SystemExit
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 set_note_attribute(data): """ add the link of the 'source' in the note """ na = False if data.get('link'): na = Types.NoteAttributes() # add the url na.sourceURL = data.get('link') # add the object to the note return na
def set_note_attribute(self, data): """ add the link of the 'source' in the note get a NoteAttributes object """ na = False if 'link' in data: na = Types.NoteAttributes() # add the url na.sourceURL = data['link'] # add the object to the note return na
def test_sync_with_unicode_place(self): """Test sync with unicode place from #186""" place_name = u"rasserie André" self._create_remote_note( attributes=ttypes.NoteAttributes( placeName=place_name.encode('utf8'), ) ) self.sync.notes_remote() self.assertTrue( self.sq(Place).filter(Place.name == place_name).count(), )
def update_note(self, note, new_title, url): '''Update note title for processed notes''' note.title = new_title attrs = Types.NoteAttributes() attrs.sourceURL = url note.attributes = attrs # Update the note with new_title try: updated_note = self.note_store.updateNote(note) return updated_note.guid except Exception as e: print('Exception while updating note: ', e) return None
def push_task(self, task_id, task, extra): """ Push task from Todoist to Evernote and save extra information in the "extra" field """ client = utils.get_evernote_client(self.user) note_store = client.get_note_store() if task_id: try: note = note_store.getNote(task_id, True, True, False, False) create = False except EDAMNotFoundException: note = Types.Note() create = True else: note = Types.Note() create = True note.title = plaintext_content(task.content, cut_url_pattern='evernote.com') if create: note.content = utils.format_note_content('') note.notebookGuid = self.notebook_guid note.attributes = Types.NoteAttributes() note.attributes.reminderOrder = REMINDER_BASE_TIME - task.item_order if task.checked: note.attributes.reminderDoneTime = int(time.time()) else: note.attributes.reminderDoneTime = None if task.due_date: due_date_ms = int((task.due_date - EPOCH).total_seconds()) * 1000 note.attributes.reminderTime = due_date_ms else: note.attributes.reminderTime = None if create: note = note_store.createNote(note) else: note = note_store.updateNote(note) new_extra = { 'original_content': task.content, 'original_due_date': task.due_date, 'original_date_string': task.date_string, } return note.guid, new_extra
def generate_note(self): ''' returns a note object with current values ''' note = ttypes.Note() note.title = self.title note.guid = self.guid attributes = ttypes.NoteAttributes() attributes.placeName = self.place attributes.sourceApplication = 'LogisticsApp' note.attributes = attributes note.tagNames = self.conditions note.content = self.write_content() return note
def _make_note(self, title, content, url): '''Prepare a note to be posted''' note = Types.Note() note.title = title # Set up note attributes attrs = Types.NoteAttributes() attrs.sourceURL = url note.attributes = attrs note.content = '<?xml version="1.0" encoding="UTF-8"?>' note.content += '<!DOCTYPE en-note SYSTEM ' \ '"http://xml.evernote.com/pub/enml2.dtd">' # Wrap content in <en-note> note.content += '<en-note>' note.content += content note.content += '</en-note>' return note
def create_note(self, notebook_guid, note_file, attachments, title_override=None): data = self.zip_file.read(note_file.full_name) info = etree.fromstring(data) note = Types.Note() note.notebookGuid = notebook_guid note.title = title_override or \ info.xpath("//note/title")[0].text.replace("\t", " ").strip().encode('utf-8') note.created = get_milliseconds_from_utc( info.xpath("//note/created")[0].text) note.updated = get_milliseconds_from_utc( info.xpath("//note/updated")[0].text) note.attributes = Types.NoteAttributes() note.attributes.author = info.xpath( "//note/note-attributes/author")[0].text.encode('utf-8') content = info.xpath("//note/content")[0].text if notebook_guid in self.already_createds \ and note.created in self.already_createds[notebook_guid]: plunk('"') raise NoteAlreadyExists plunk(".") if len(attachments): plunk("@") note.resources = [self.create_attachment(attachment) \ for attachment in attachments] attachment_xml = "<br /><br />" for attachment in note.resources: hash_hex = binascii.hexlify(attachment.data.bodyHash) attachment_xml += '<en-media type="%s" hash="%s"/>' % ( attachment.mime, hash_hex) content = content.replace("</en-note>", attachment_xml + "</en-note>") note.content = content.encode('utf-8') note.tagNames = extract_tags(content) if len(note.tagNames): plunk("#") self.note_store.createNote(note) return note
def make_note_obj(notebook, title, post, location): # extract tags from the post tag_names = re.findall("#(\w+)", post) # make the note note = Types.Note() note.title = DEFAULT_NOTE_TITLE note.content = NOTE_TEMPLATE % cgi.escape(post) note.notebookGuid = notebook note.tagNames = tag_names # add in geolocation if we have it loc_lat, loc_long = location if loc_lat and loc_long: note_attr = Types.NoteAttributes() note_attr.latitude = float(loc_lat) note_attr.longitude = float(loc_long) note.attributes = note_attr return note
def create_new_note(items, place, category, conditions): ''' Returns note object given items, place, category, conditions :param items: :param place: :param category: :param conditions: list :return: ''' new_note = ttypes.Note() new_note.guid = None new_note.title = category newAttributes = ttypes.NoteAttributes() newAttributes.placeName = place newAttributes.sourceApplication = 'LogisticsApp' if conditions: new_note.tagNames = conditions noteBody = write_note_checklist(items) new_note.content = write_note_body(noteBody) new_note.attributes = newAttributes return new_note
def process_email(self, email): # Plain is given as a list - in case of multipart perhaps? # 1. Identify URL's in email plain = ' '.join(email.body['plain']) urls = extract_urls_from_text(plain) # NOTE: what to do about multiple links? include all of them? For now, # just choose the first one. url = urls[0] # 2. Extract URL content title, text = extract_url_content(url) # 3. Add to EverNote note = Types.Note() note.title = title note.content = text_to_enml(text).encode('utf8') attributes = Types.NoteAttributes() attributes.sourceURL = url note.attributes = attributes note = self.noteStore.createNote(note)
def save_data(self, token, trigger_id, **data): """ let's save the data dont want to handle empty title nor content otherwise this will produce an Exception by the Evernote's API """ content = '' if 'content' in data: if type(data['content']) is list: if 'value' in data['content'][0]: content = data['content'][0].value else: if 'value' in data['content']: content = data['content']['value'] else: content = data['content'] elif 'summary_detail' in data: if type(data['summary_detail']) is list: if 'value' in data['summary_detail'][0]: content = data['summary_detail'][0].value else: if 'value' in data['summary_detail']: content = data['summary_detail']['value'] else: content = data['summary_detail'] elif 'description' in data: content = data['description'] # if no title provided, fallback to the URL which should be provided # by any exiting service title = (data['title'] if 'title' in data else data['link']) if token and len(title): # get the evernote data of this trigger trigger = Evernote.objects.get(trigger_id=trigger_id) client = EvernoteClient( token=token, sandbox=settings.TH_EVERNOTE['sandbox']) # user_store = client.get_user_store() note_store = client.get_note_store() # note object note = Types.Note() if trigger.notebook: notebooks = note_store.listNotebooks() listtags = note_store.listTags() notebookGuid = 0 tagGuid = [] # get the notebookGUID ... for notebook in notebooks: if notebook.name.lower() == trigger.notebook.lower(): notebookGuid = notebook.guid break #... and get the tagGUID if a tag has been provided if trigger.tag is not '': # cut the string by piece of tag with comma if ',' in trigger.tag: for my_tag in trigger.tag.split(','): for tag in listtags: # remove space before and after # thus we keep "foo bar" # but not " foo bar" nor "foo bar " if tag.name.lower() == my_tag.lower().lstrip().rstrip(): tagGuid.append(tag.guid) break else: for tag in listtags: if tag.name.lower() == my_tag.lower(): tagGuid.append(tag.guid) break # notebookGUID does not exist: # create it if notebookGuid == 0: new_notebook = Types.Notebook() new_notebook.name = trigger.notebook new_notebook.defaultNotebook = False note.notebookGuid = note_store.createNotebook( new_notebook).guid else: note.notebookGuid = notebookGuid # tagGUID does not exist: # create it if a tag has been provided if tagGuid == 0 and trigger.tag is not '': new_tag = Types.Tag() new_tag.name = trigger.tag tagGuid = note_store.createTag(new_tag).guid if trigger.tag is not '': # set the tag to the note if a tag has been provided note.tagGuids = tagGuid logger.debug("notebook that will be used %s", trigger.notebook) if 'link' in data: # add the link of the 'source' in the note # get a NoteAttributes object na = Types.NoteAttributes() # add the url na.sourceURL = data['link'] # add the object to the note note.attributes = na # will add this kind of info in the footer of the note : # "provided by FoxMaSk's News from http://domain.com" # domain.com will be the link and the text of the link provided_by = _('Provided by') provided_from = _('from') footer_from = "<br/><br/>{} <em>{}</em> {} <a href='{}'>{}</a>" footer = footer_from.format( provided_by, trigger.trigger.description, provided_from, data['link'], data['link']) content += footer # start to build the "note" # the title note.title = title # the body prolog = '<?xml version="1.0" encoding="UTF-8"?>' prolog += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' note.content = prolog # tidy and sanitize content enml = sanitize(content) note.content += str(enml) # create the note ! try: created_note = note_store.createNote(note) sentance = str('note %s created') % created_note.guid logger.debug(sentance) except Exception as e: logger.critical(e) else: sentence = "no token provided for trigger ID {} and title {}" logger.critical(sentence.format(trigger_id, title))
def attributes(self): ret = Types.NoteAttributes() ret.sourceURL = self.recipe.detail_url return ret
def updateNote(self, guid, title=None, content=None, tags=None, created=None, notebook=None, resources=None, reminder=None, url=None): note = Types.Note() note.guid = guid if title: note.title = title if content: 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 = 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) if not note.content: note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note></en-note>' note.content = note.content.replace("</en-note>", resource_nodes + "</en-note>") if reminder: if not note.attributes: # in case no attributes available note.attributes = Types.NoteAttributes() now = int(round(time.time() * 1000)) if reminder == config.REMINDER_NONE: note.attributes.reminderDoneTime = None note.attributes.reminderTime = None if not note.attributes.reminderOrder: # new reminder note.attributes.reminderOrder = now elif reminder == config.REMINDER_DONE: note.attributes.reminderDoneTime = now if not note.attributes.reminderOrder: # catch adding DONE to non-reminder note.attributes.reminderOrder = now note.attributes.reminderTime = None elif reminder == config.REMINDER_DELETE: note.attributes.reminderOrder = None note.attributes.reminderTime = None note.attributes.reminderDoneTime = None else: # we have an actual reminder timestamp if reminder > now: # future reminder only note.attributes.reminderTime = reminder note.attributes.reminderDoneTime = None if not note.attributes.reminderOrder: # catch adding time to non-reminder note.attributes.reminderOrder = now else: out.failureMessage( "Sorry, reminder must be in the future.") tools.exitErr() if url: if not note.attributes: # in case no attributes available note.attributes = Types.NoteAttributes() note.attributes.sourceURL = url logging.debug("Update note : %s", note) self.getNoteStore().updateNote(self.authToken, note) return True
for tweet in favorites: try: # Create new note note = Types.Note() note.title = tweet['text'][:30].encode('utf-8') # Add content 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/>' % tweet['text'].encode('utf-8') note.content += '</en-note>' # Set tag note.tagNames = ["#twitter"] # Set attributes noteAttributes = Types.NoteAttributes() noteAttributes.sourceURL = "https://twitter.com/statuses/%s" % tweet['id'] note.attributes = noteAttributes # Save to Evernote created_note = note_store.createNote(note) # Unsave it on twitter twitterApi.destroy_favorite(tweet['id']) print("Processed %s" % tweet['id']) except: print("Failed to process %s" % tweet['id'])
result_list = note_store.findNotes(updated_filter, offset, max_notes) def read_file(file): with open(file, 'r', encoding='utf-8') as f: data = f.read() return data # 创建Note dir_name = 'F:\zkl_repository\jianzhiffer_with_java\牛客网-华为机试练习题\md' docList = os.listdir(dir_name) #特定目录下的文件存入列表 docList.sort() # 显示当前文件夹下所有文件并进行排序 ignore_file = ['all.md'] docList = [item for item in docList if item not in ignore_file] attribute = Types.NoteAttributes() #attribute.contentClass='yinxiang.markdown' for item in docList: note = Types.Note() note.title = item fname = os.path.join(dir_name, item) data = read_file(fname) 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>' + data note.content += '</en-note>' note.notebookGuid = selected_book.guid note.attributes = attribute created_note = note_store.createNote(auth_token, note)
def create_note(self, issue: Issue, jira_man: JiraManager): # ______________________________ # Note object note = ttypes.Note() note.notebookGuid = self._notebook.guid # ______________________________ # Attributes issue_url = jira_man.get_url(issue.key) note.attributes = ttypes.NoteAttributes(sourceURL=issue_url) note.tagNames = self._config.evernote_tags # ______________________________ # Title try: note.title = issue.fields.parent.key + " - " + self._get_safe_text(issue.fields.summary) except: note.title = issue.key + " - " + self._get_safe_text(issue.fields.summary) # ______________________________ # Body # Header body = '<?xml version="1.0" encoding="UTF-8"?>' body += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' body += '<en-note>' # URL body += 'Madde: <a href="' + issue_url + '">' + issue_url + '</a><br/>' try: parent_url = jira_man.get_url(issue.fields.parent.key) body += 'Üst madde: <a href="' + parent_url + '">' + parent_url + '</a><br/>' except: pass # Summary summary = "" try: summary = self._get_safe_text(issue.fields.summary) except: pass try: summary2 = self._get_safe_text(issue.fields.description) summary += "<br/><br/>" + summary2 except: pass body += '<br/>' + summary + '<br/><br/>' # To do body += '<hr/><b>İşler</b><br/><br/>' body += '<en-todo/>Jira''yı ilerlet<br/><br/>' body += '<en-todo/>Geliştirme<br/><br/>' body += '<en-todo/>EPC + Task Release<br/><br/>' body += '<en-todo/>Teknik test<br/><br/>' body += '<en-todo/>Jira''yı ilerlet ve yorum yaz<br/><br/>' # Comments for i in range(self._config.evernote_comment_count): comment_idx = issue.fields.comment.total - 1 - i if comment_idx < 0: break if i == 0: body += '<hr/><b>Son yorumlar</b><br/><br/>' current_comment = issue.fields.comment.comments[comment_idx] comment_body = self._get_safe_text(current_comment.body).replace("\r\n", "<br/>") body += '<b>' + current_comment.author.displayName + ", " + current_comment.created + ':</b> <br/>' + comment_body + "<br/><br/>" # Bottom body += '<br/><hr/><br/>' # Finish body += '</en-note>' note.content = body # ______________________________ # Flush self._note_store.createNote(note)