def notes_local(self): """Send local notes changes to server""" for note in self.sq(models.Note).filter( and_( models.Note.action != ACTION_NONE, models.Note.action != ACTION_NOEXSIST, models.Note.action != ACTION_CONFLICT, )): self.app.log('Note %s local' % note.title) content = (u""" <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note>%s</en-note> """ % sanitize(html=note.content[:EDAM_NOTE_CONTENT_LEN_MAX]) ).strip().encode('utf8') soup = BeautifulStoneSoup(content, selfClosingTags=[ 'img', 'en-todo', 'en-media', 'br', 'hr', ]) kwargs = dict( title=note.title[:EDAM_NOTE_TITLE_LEN_MAX].strip().encode( 'utf8'), content=soup.prettify(), tagGuids=map( lambda tag: tag.guid, note.tags, ), ) if note.notebook: kwargs['notebookGuid'] = note.notebook.guid if note.guid: kwargs['guid'] = note.guid nt = Note(**kwargs) try: next_action = ACTION_NONE if note.action == ACTION_CHANGE: nt.resources = self._resources_for_note(note) nt = self.note_store.updateNote(self.auth_token, nt) elif note.action == ACTION_CREATE: nt.resources = self._resources_for_note(note) nt = self.note_store.createNote(self.auth_token, nt) note.guid = nt.guid elif note.action == ACTION_DELETE: self.note_store.deleteNote(self.auth_token, nt.guid) self.session.delete(note) except EDAMUserException as e: next_action = ACTION_NONE self.app.log('Note %s failed' % note.title) self.app.log(e) note.action = next_action self.session.commit()
def _prepare_content(self, content): """Prepare content""" enml_content = (u""" <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note>{}</en-note> """.format(sanitize( html=content[:limits.EDAM_NOTE_CONTENT_LEN_MAX] ))).strip().encode('utf8') soup = BeautifulSoup(enml_content, selfClosingTags=[ 'img', 'en-todo', 'en-media', 'br', 'hr', ]) return str(soup)
def content(self): """Cache content and return""" soup = BeautifulSoup(self.page.mainFrame().toHtml()) for todo in soup.findAll("input", {"type": "checkbox"}): todo.name = "en-todo" if todo.get("checked") == "false": del todo["checked"] del todo["type"] for media in soup.findAll("img"): if media.get("class") == "tab": media.replaceWith(" " * 5) if media.get("hash"): media.name = "en-media" del media["src"] self._content = sanitize(soup=soup.find(id="content")).replace(" ", u"\xa0 ") return self._content
def notes_local(self): """Send loacl notes changes to server""" for note in self.sq(models.Note).filter(and_( models.Note.action != ACTION_NONE, models.Note.action != ACTION_NOEXSIST, )): self.app.log('Note %s local' % note.title) content = (u""" <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note>%s</en-note> """ % sanitize( html=note.content[:EDAM_NOTE_CONTENT_LEN_MAX] )).strip().encode('utf8') soup = BeautifulStoneSoup(content, selfClosingTags=[ 'img', 'en-todo', 'en-media', 'br', 'hr', ]) kwargs = dict( title=note.title[:EDAM_NOTE_TITLE_LEN_MAX].strip().encode('utf8'), content=soup.prettify(), tagGuids=map( lambda tag: tag.guid, note.tags, ), ) if note.notebook: kwargs['notebookGuid'] = note.notebook.guid if note.guid: kwargs['guid'] = note.guid nt = Note(**kwargs) try: next_action = ACTION_NONE if note.action == ACTION_CHANGE: nt.resources = self._resources_for_note(note) nt = self.note_store.updateNote(self.auth_token, nt) elif note.action == ACTION_CREATE: nt.resources = self._resources_for_note(note) nt = self.note_store.createNote(self.auth_token, nt) note.guid = nt.guid elif note.action == ACTION_DELETE: self.note_store.deleteNote(self.auth_token, nt.guid) self.session.delete(note) except EDAMUserException as e: next_action = note.action self.app.log('Note %s failed' % note.title) print soup.prettify() print e note.action = next_action self.session.commit()
def content(self): """Cache content and return""" soup = BeautifulSoup(self.page.mainFrame().toHtml()) for todo in soup.findAll('input', {'type': 'checkbox'}): todo.name = 'en-todo' if todo.get('checked') == 'false': del todo['checked'] del todo['type'] for media in soup.findAll('img'): if media.get('class') == 'tab': media.replaceWith(' ' * 5) if media.get('hash'): media.name = 'en-media' del media['src'] self._content = sanitize(soup=soup.find(id='content'), ).replace( ' ', u'\xa0 ') return self._content
def content(self): """Cache content and return""" soup = BeautifulSoup(self.page.mainFrame().toHtml()) for todo in soup.findAll('input', {'type': 'checkbox'}): todo.name = 'en-todo' if todo.get('checked') == 'false': del todo['checked'] del todo['type'] for media in soup.findAll('img'): if media.get('class') == 'tab': media.replaceWith(' ' * 5) if media.get('hash'): media.name = 'en-media' del media['src'] self._content = sanitize( soup=soup.find(id='content'), ).replace(' ', u'\xa0 ') return self._content
def _prepare_content(self, content): """Prepare content""" enml_content = (u""" <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note>{}</en-note> """.format(sanitize(html=content[:limits.EDAM_NOTE_CONTENT_LEN_MAX])) ).strip().encode('utf8') soup = BeautifulSoup(enml_content, selfClosingTags=[ 'img', 'en-todo', 'en-media', 'br', 'hr', ]) return str(soup)
def _prepare_content(self, content): """Prepare content""" enml_content = ( ( u""" <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> <en-note>{}</en-note> """.format( sanitize(html=content[: limits.EDAM_NOTE_CONTENT_LEN_MAX]) ) ) .strip() .encode("utf8") ) BeautifulSoup.NESTABLE_TAGS["li"] = ["ul", "ol"] BeautifulSoup.NESTABLE_TAGS["ul"] = ["li"] BeautifulSoup.NESTABLE_TAGS["ol"] = ["li"] soup = BeautifulSoup(enml_content, selfClosingTags=["img", "en-todo", "en-media", "br", "hr"]) return str(soup)