Exemplo n.º 1
0
    def get(self, file_id):
        client = self.get_authorized_client()
        if not client:
            return self.redirect('/auth-evernote?next={0}'.format(self.request.path))

        try:
            file = self.get_file(file_id)
        except webapp2.HTTPException as http_ex:
            if http_ex.code == 401:
                return self.redirect('/auth?next={0}'.format(self.request.path))

        base_url = self.request.host_url + '/edit/{0}'.format(file['id'])
        extension_loaded = bool(int(self.request.get('extensionLoaded', 1)))

        # Look for the VideoNot.es Notebook
        notestore = client.get_note_store()
        notesbooks = notestore.listNotebooks()
        notebook = None

        for a_notesbook in notesbooks:
            if a_notesbook.name == 'VideoNot.es':
                notebook = a_notesbook
                break

        if not notebook:
            notebook = Notebook()
            notebook.name = 'VideoNot.es'
            notebook = notestore.createNotebook(notebook)

        # Formatting the note in ENML
        content_enml = FileUtils.to_ENML(file, base_url)
        content_enml.append('<br></br><br></br>')

        content_enml.append('<a href="{0}">View in VideoNot.es</a>'.format(base_url))
        if not extension_loaded:
            content_enml.append('<br/>')
            content_enml.append('(Tip: you can add snapshots of the video to your export by installing our <a href="https://chrome.google.com/webstore/detail/kmbcnighpdagelfjmlbakfnciogcelgi">Chrome Extension</a>)')

        # Saving the note in Evernote
        note = Note()
        note.title = file['title']
        note_content = ''.join(content_enml).encode('utf-8')
        note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>{0}</en-note>'.format(note_content)
        note.content = note.content.replace('&', '&amp;')
        if notebook:
            note.notebookGuid = notebook.guid
        note = notestore.createNote(note)

        logging.debug('VideoNot.es %s exported to Evernote: %s', file_id, note_content)
        logging.info('VideoNot.es %s exported to Evernote with id: %s', file_id, note.guid)

        # Returning to the new note in Evernote
        user_store = client.get_user_store()
        notestore_url = '/'.join(user_store.getNoteStoreUrl().split('/')[0:5])
        return self.redirect(notestore_url + '/view/notebook/{0}'.format(note.guid))
Exemplo n.º 2
0
def tset_notebook(store, name):
    """Return notebook with specific name.
    Create a new notebook if there isn't an existing one.
    """
    notebooks = store.listNotebooks()
    notebook = [nb for nb in notebooks if nb.name == name]
    if notebook:
        log('Found notebook {}'.format(name))
        return notebook[0]
    else:
        notebook = Notebook()
        notebook.name = name
        notebook.defaultNotebook = False
        log('Create new notebook {}'.format(name))
        return store.createNotebook(dev_token, notebook)
Exemplo n.º 3
0
def tset_notebook(store, name):
    """Return notebook with specific name.
    Create a new notebook if there isn't an existing one.
    """
    notebooks = store.listNotebooks()
    notebook = [nb for nb in notebooks if nb.name == name]
    if notebook:
        log('Found notebook {}'.format(name))
        return notebook[0]
    else:
        notebook = Notebook()
        notebook.name = name
        notebook.defaultNotebook = False
        log('Create new notebook {}'.format(name))
        return store.createNotebook(dev_token, notebook)
Exemplo n.º 4
0
def evernote_create_notebook(request):
    if request.method != 'POST':
        return redirect('/api')

    name = request.POST.get('notebook')

    note_store = get_note_store()
    response_data = {}

    newNotebook = Notebook()
    newNotebook.name = name

    notebook = None
    try:
        notebook = note_store.createNotebook( newNotebook )
        response_data['result'] = "success"
    except:
        response_data['result'] = "error"

    return HttpResponse(
        json.dumps(response_data),
        content_type="application/json"
    )
Exemplo n.º 5
0
 def create_or_update_note(self, new_note):
     """ Create new note or update existing one if there's any with provided tile
     Arguments:
     new_note  -- new note dictionary with the following items:
       'title'    -- note title, should be unique, this field is used to search for existing note
       'content'  -- note data in ENML markup. See https://dev.evernote.com/doc/articles/enml.php
       'notebook' -- name of the notebook to create note in (ignored on 'update')
       'created'  -- note creation time in milliseconds from epoch
       'updated'  -- note last updated time in milliseconds from epoch
     """
     note_title = new_note.get('title')
     note_contents = new_note.get('content')
     notebook_name = new_note.get('notebook')
     note_created = new_note.get('created')
     note_updated = new_note.get('updated')
     note = self.find_note(note_title)
     if note:
         note.content = note_contents
         note.created = note_created
         note.updated = note_updated
         Evernote.call_method(self.note_store.updateNote, note)
     else:
         note = Note()
         note.title, note.content = note_title, note_contents
         note.created, note.updated = note_created, note_updated
         for notebook in Evernote.call_method(self.note_store.listNotebooks):
             if notebook.name == notebook_name:
                 note.notebookGuid = notebook.guid
                 break
         else:
             if notebook_name:
                 # Notebook not found, create new one
                 notebook = Notebook()
                 notebook.name = notebook_name
                 notebook = Evernote.call_method(self.note_store.createNotebook, notebook)
                 note.notebookGuid = notebook.guid
         Evernote.call_method(self.note_store.createNote, note)
Exemplo n.º 6
0
# dev_token = ""
# client = EvernoteClient(token=dev_token, service_host='sandbox.yinxiang.com')

# 这个是正式账号
prod_token = ""
client = EvernoteClient(token=prod_token, service_host='app.yinxiang.com')

userStore = client.get_user_store()
user = userStore.getUser()
print(user.username)

# --- 加笔记本
# 第一件事,get_note_store
noteStore = client.get_note_store()
notebook = Notebook()
notebook.name = "My Notebook"
notebook = noteStore.createNotebook(notebook)
print(notebook.guid)

# --- 加笔记
noteStore = client.get_note_store()
note = Note()
note.title = "I'm a test note!"
note.content = '<?xml version="1.0" encoding="UTF-8"?>' \
               '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
note.content += '<en-note>Hello, world!</en-note>'
# 如果不附notebookGUID的话会创建到默认笔记本里
note.notebookGuid = notebook.guid
note = noteStore.createNote(note)

# --- 搜索笔记
Exemplo n.º 7
0
def main():
    client = EvernoteClient(token=dev_token, sandbox=False)
    noteStore = client.get_note_store()
    noteStore = client.get_note_store()
    Filter=NodeTypes.NoteFilter()
    Filter.words = 'tag:@smarttodo'
    notes = noteStore.findNotes(dev_token, Filter, 0, 10)
    for note in notes.notes:
        nt = noteStore.getNote(dev_token, note.guid, True, False, False, False)
        root = ElementTree.fromstring(nt.content)
        ElementTree.dump(root)
        sections = split_into_sections(root)
        today = datetime.date.today() - datetime.timedelta(1)
        tomorrow = today + datetime.timedelta(1)
        conversions = {
            'today': today,
            'tomorrow': tomorrow,
            'yesterday': today - datetime.timedelta(1),
        }
        print sections
        unfinished = parse_out_due_dates(sections['today'][1:], today, conversions,
                                         sections['settings']['Date format'])
        unfinished.extend(
            parse_out_due_dates(sections['later'][1:], tomorrow, conversions,
                                sections['settings']['Date format']))
        new_today_list = [x for x in unfinished if x[0] <= tomorrow]
        new_tomorrow_list = [x for x in unfinished if x[0] > tomorrow]
        new_tomorrow_list.sort(key=lambda x: x[0])
        sections['today'][1:] = update_tasks(new_today_list, sections['settings']['Date format'], sections['settings']['Date separator'])
        sections['later'][1:] = update_tasks(new_tomorrow_list, sections['settings']['Date format'], sections['settings']['Date separator'])
        text, tail, attrib, tag = root.text, root.tail, root.attrib, root.tag
        root.clear()
        root.text, root.tail, root.attrib, root.tag = text, tail, attrib, tag
        for sec in ['start', 'today', 'later', 'end']:
            for section in sections[sec]:
                if sec in ['today', 'later']:
                    root.extend(section)
                else:
                    root.append(section)
        while len(root) > 0 and root[-1].tag == 'br':
            root.remove(root[-1])
        new_node_content = ElementTree.tostring(root, 'utf-8')
        nt.content = content_prefix + new_node_content
        print 'Updated:'
        ElementTree.dump(root)
        noteStore.updateNote(dev_token, nt)

        if len(sections['completed']) <= 0:
            continue
        history_notebook = sections['settings']['History notebook'].strip()
        history_interval = sections['settings']['History interval'].strip()
        history_prefix = sections['settings']['History note'].strip()
        history_title = get_history_note_title(history_prefix, today,
                                               history_interval,
                                               sections['settings']['Date format'],
                                               sections['settings']['Date separator'])
        notebooks = noteStore.listNotebooks(dev_token)
        notebook_guid = None
        for notebook in notebooks:
            if notebook.name == history_notebook:
                notebook_guid = notebook.guid
        if notebook_guid == None:
            notebook = Notebook()
            notebook.name = history_notebook
            notebook = noteStore.createNotebook(dev_token, notebook)
            notebook_guid = notebook.guid
        Filter = NodeTypes.NoteFilter()
        Filter.notebookGuid = notebook_guid
        Filter.words = 'intitle:' + history_title
        history_notes = noteStore.findNotes(dev_token, Filter, 0, 1)
        if len(history_notes.notes) < 1:
            hist_root = ElementTree.Element('en-note')
            hist_note = Note()
            hist_note.title = history_title
            hist_note.notebookGuid = notebook_guid
        else:
            hist_note = noteStore.getNote(dev_token, history_notes.notes[0].guid,
                                          True, False, False, False)
            hist_root = ElementTree.fromstring(hist_note.content)
        day_element = ElementTree.fromstring('<div><strong>{}</strong></div>'.format(
            date_to_string(today,
                           sections['settings']['Date format'],
                           sections['settings']['Date separator'])))
        hist_root.append(day_element)
        for x in sections['completed']:
            hist_root.extend(x)
        hist_note.content = content_prefix + ElementTree.tostring(hist_root, 'utf-8')
        if len(history_notes.notes) < 1:
            noteStore.createNote(dev_token, hist_note)
        else:
            noteStore.updateNote(dev_token, hist_note)