LKEvernoteApi.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pythonista-scripts 作者: lukaskollmer 项目源码 文件源码
def append_to_note(guid, new_content, main_new_content, add_if_already_exists):

    #Get the note to be updated using the note's guid http://dev.evernote.com/documentation/reference/NoteStore.html#Fn_NoteStore_getNote
    note_store = _get_note_store()

    log_progress('load the \'2Archive\' note')
    note = note_store.getNote(guid, True, True, False, False)

    #Regular expressions used to replicate ENML tags.  These same tags will be used to "rebuild" the note with the existing note metadata
    log_progress('do the regEx stuff')
    xmlTag          = re.search('<\?xml.*?>', note.content).group()
    docTag          = re.search('<\!DOCTYPE.*?>', note.content).group()
    noteOpenTag     = re.search('<\s*en-note.*?>', note.content).group()
    noteCloseTag    = re.search('<\s*/en-note.*?>', note.content).group()
    breakTag        = '<br />'

    #Rebuild the note using the new content
    log_progress('Rebuild the note using the new content')
    content           =  note.content.replace(xmlTag, "").replace(noteOpenTag, "").replace(noteCloseTag, "").replace(docTag, "").strip()

    if main_new_content in content:
        if add_if_already_exists:
            content += breakTag + "".join(new_content)
        else:
            log_progress('url already in note')
    else:
        content += breakTag + ''.join(new_content)
    template          =  Template ('$xml $doc $openTag $body $closeTag')
    note.content      =  template.substitute(xml=xmlTag,doc=docTag,openTag=noteOpenTag,body=content,closeTag=noteCloseTag)

    #Update the note

    log_progress('save the updated note to evernote')
    try:
        _get_note_store().updateNote(note)
    except:
        print sys.exc_info()

    #Return updated note (object) to the function
    return note
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号