Esempio n. 1
0
def init_note(guid, content):

    # Initializing the note object
    note = Note()
    note.content = content
    note.guid = guid

    # Getting note title
    soup = BeautifulSoup(content, "html.parser")
    note.title = soup.title.text

    # Initializing variables
    resources = []
    resource = None
    data = None
    binaryData = None
    hash = None

    # Getting note resources
    path = safeglobals.path_note % (guid, "")
    for filename in os.listdir(path):
        if "content.json" not in filename:

            # Reading binary data
            with open(os.path.join(path, filename), "rb") as f:
                binaryData = f.read()

            # Calculating hash
            md5 = hashlib.md5()
            md5.update(binaryData)
            hash = md5.digest()

            # Creating data
            data = Data()
            data.size = len(binaryData)
            data.bodyHash = hash
            data.body = binaryData

            # Create a new resource
            resource = Resource()
            resource.mime = getMime(filename)
            resource.data = data

            # Creating attributes
            attributes = ResourceAttributes()
            attributes.fileName = filename

            # Adding the resource to resource collection
            resource.attributes = attributes
            resources.append(resource)

    # Adding resources to the specified note
    note.resources = resources
    return note
Esempio n. 2
0
                },
                'item 2': {
                    'location': '354e3b76-c78a-4f0f-bc1e-2f9115f09176',
                    'delete': None
                }
            }
        },
        'return': {
            'guid': '454e3b76-c78a-4f0f-bc1e-2f9115f09177',
            'add_pointer': 'no add btn assigned yet',
            'items': {
                'item 1': {
                    'location': '354e3b76-c78a-4f0f-bc1e-2f9115f09176',
                    'delete': None
                },
                'item 2': {
                    'location': '354e3b76-c78a-4f0f-bc1e-2f9115f09176',
                    'delete': None
                }
            }
        },
    },
    'place': 'walmart'
}

note_obj = Note()
note_obj.guid = 'offline_test_guid'

conditions = {'guid_tag': 'random_tag'}
places = ['walmart', 'Custom']
Esempio n. 3
0
    token = f.read()
client = EvernoteClient(token=token, service_host='app.yinxiang.com')

# 获取笔记本
noteStore = client.get_note_store()
# notebooks = noteStore.listNotebooks()
guid_notebook = '2d083d6b-b84e-4dea-b6de-e4fa42d8fd72'
notebook = noteStore.getNotebook(guid_notebook)  # OneNote迁移 笔记本
guid_notebook_bak = '9a93a8dc-d863-4621-8ab5-c91f4fdf8576'
notebook_bak = noteStore.getNotebook(guid_notebook_bak)  # 迁移备份 笔记本

# 查找笔记
filter = NoteStore.NoteFilter()
filter.notebookGuid = guid_notebook_bak  # TODO 之后改回去
spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
notes = noteStore.findNotesMetadata(filter, 0, 200, spec).notes
for noteMeta in notes:
    # 先备份一下
    noteStore.copyNote(noteMeta.guid, guid_notebook_bak)
    # 开始改内容
    note = noteStore.getNote(noteMeta.guid, True, True, True, True)
    content = note.content
    new_content = clean_content(content)
    # 更新笔记
    new_note = Note()
    new_note.guid = note.guid
    new_note.title = note.title
    new_note.content = new_content
    noteStore.updateNote(new_note)
Esempio n. 4
0
def imglist2note(notestore, imglist, noteguid, notetitle, neirong=''):
    """
    更新note内容为图片列表
    :param notestore:
    :param imglist:
    :param noteguid:
    :param notetitle:
    :param neirong:object
    :return:
    """
    # global log
    note = Note()
    # print(type(note))
    note.guid = noteguid
    note.title = notetitle

    # 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.

    # Now, add the new Resource to the note's list of resources
    # print(len(note.resources))
    # print(noteguid)
    # note.resources = notestore.getNote(token, noteguid, True, True, True,True).resources
    # evernoteapijiayi()
    # if not note.resources:
    #     note.resources = []

    note.resources = []
    # print(len(note.resources))
    # for img, imgtitle in imglist:
    for img in imglist:
        image = open(img, 'rb').read()
        md5 = hashlib.md5()
        md5.update(image)
        imghash = md5.digest()
        data = Data()  # 必须要重新构建一个Data(),否则内容不会变化
        data.size = len(image)
        data.bodyHash = imghash
        data.body = image
        resource = Resource()
        resource.mime = 'image/png'
        resource.data = data
        note.resources.append(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
    nbody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    nbody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
    nbody += "<en-note>"
    if note.resources:
        # 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.
        # nBody += "<br />" * 2
        for resource in note.resources:
            if resource.guid or True:
                hexhash = binascii.hexlify(resource.data.bodyHash)
                str1 = "%s" % hexhash  # b'cd34b4b6c8d9279217b03c396ca913df'
                # print (str1)
                str1 = str1[2:-1]  # cd34b4b6c8d9279217b03c396ca913df
                # print (str1)
                nbody += "<en-media type=\"%s\" hash=\"%s\" align=\"center\" /><br />" % (
                    resource.mime, str1)
    nbody += neirong
    nbody += "</en-note>"

    note.content = nbody
    # print (note.content)

    # Finally, send the new note to Evernote using the updateNote method
    # The new Note object that is returned will contain server-generated
    # attributes such as the new note's unique GUID.
    @trycounttimes2('evernote服务器')
    def updatenote(notesrc):
        updated_note = get_notestore().updateNote(notesrc)
        evernoteapijiayi()
        log.info('成功更新了笔记《%s》,guid:%s。' %
                 (updated_note.title, updated_note.guid))

    updatenote(note)