折腾:
【未解决】Python中如何更新印象笔记中note笔记中的附件图片
期间,先去搞懂,如何获取单个note的详细数据,包括资源列表。
那对于单个note,如何获取其resource?
说是:
自己解析note中的内容,找到en-media的tag的,通过type和hash去判断
此处图片,应该就是找到type=image/xxx的
TODO:看到附件除了图片还有其他音频和pdf的:
* audio/wav
* audio/mpeg
* audio/amr
* application/pdf
-》说明以后还要抽空去:
把note中带audio和pdf的,都当做文件上传到WordPress中,再去替换成文件链接地址
对于找到了image后,可以通过
去获取到该图片
另外一种方式是:
每个note都有一个resources属性
去看看
感觉需要获取到note的详情才行
去看看此处如何调用
自己此处去代码中搜:
getNote(
找到:
libs/evernote-sdk-python3/lib/evernote/edam/notestore/NoteStore-remote
print ' Note getNote(string authenticationToken, Guid guid, bool withContent, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData)'
libs/evernote-sdk-python3/lib/evernote/edam/notestore/NoteStore.py
def getNote(self, authenticationToken, guid, withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData): """ Returns the current state of the note in the service with the provided GUID. The ENML contents of the note will only be provided if the 'withContent' parameter is true. The service will include the meta-data for each resource in the note, but the binary contents of the resources and their recognition data will be omitted. If the Note is found in a public notebook, the authenticationToken will be ignored (so it could be an empty string). The applicationData fields are returned as keysOnly. @param guid The GUID of the note to be retrieved. @param withContent If true, the note will include the ENML contents of its 'content' field. @param withResourcesData If true, any Resource elements in this Note will include the binary contents of their 'data' field's body. @param withResourcesRecognition If true, any Resource elements will include the binary contents of the 'recognition' field's body if recognition data is present. @param withResourcesAlternateData If true, any Resource elements in this Note will include the binary contents of their 'alternateData' fields' body, if an alternate form is present. @throws EDAMUserException <ul> <li> BAD_DATA_FORMAT "Note.guid" - if the parameter is missing </li> <li> PERMISSION_DENIED "Note" - private note, user doesn't own </li> </ul> @throws EDAMNotFoundException <ul> <li> "Note.guid" - not found, by GUID </li> </ul> Parameters: - authenticationToken - guid - withContent - withResourcesData - withResourcesRecognition - withResourcesAlternateData """ self.send_getNote(authenticationToken, guid, withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData) return self.recv_getNote()
去代码中试试
此处对于:withResourcesAlternateData
不知道什么是alternate data
抽空再去研究
noteInfo = gNoteStore.getNote( authenticationToken=AuthToken, guid=eachNote.guid, withContent=True, withResourcesData=True, withResourcesRecognition=True, withResourcesAlternateData=True, )
结果报错:
发生异常: TypeError getNote() missing 5 required positional arguments: 'guid', 'withContent', 'withResourcesData', 'withResourcesRecognition', and 'withResourcesAlternateData' File "/Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/libs/evernote-sdk-python3/lib/evernote/api/client.py", line 167, in delegate_method )(**dict(list(zip(arg_names, args)))) File "/Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/EvernoteToWordpress.py", line 349, in processSingleNote withResourcesAlternateData=True, File "/Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/EvernoteToWordpress.py", line 331, in processNotes processSingleNote(eachNote) File "/Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/EvernoteToWordpress.py", line 290, in EvernoteToWordpress processNotes(curNotebook) File "/Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/EvernoteToWordpress.py", line 467, in <module> EvernoteToWordpress()
换:
noteInfo = gNoteStore.getNote(AuthToken, eachNote.guid, True, True, True)
调试发现一个奇怪的现在,guid竟然也是token

改为:
noteInfo = gNoteStore.getNote(AuthToken, eachNote.guid, True, True, True, True)
结果:好像就正常了
终于获取到note的详情了:

【总结】
此处通过:
# authenticationToken=AuthToken, # guid=eachFoundNote.guid, # withContent=True, # withResourcesData=True, # withResourcesRecognition=True, # withResourcesAlternateData=True, # ) # noteInfo = gNoteStore.getNote(AuthToken, eachFoundNote.guid, True, True, True) noteDetail = gNoteStore.getNote(AuthToken, eachFoundNote.guid, True, True, True, True)
是可以获取到note的详情,包括资源列表
2019/12/14 09:48:08 EvernoteToWordpress.py:353 INFO noteDetail=Note(guid='f3028259-c103-441f-b33a-df6148e7a79f', title='测试图片缩放和压缩', content='<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div><br /></div><div>试试把常见的图片,自动压缩</div><div>等比例压缩</div><div><br /></div><div>包括之前手机截图的固定的分辨率,要缩小</div><div><br /></div><div><br /></div><br /><en-media type="image/png" hash="0ef4433ff1b0fbe0778f26ab003287c3" /><br /><en-media type="image/png" hash="879cddd5ea4d3e3272b552f34fecfa3f" /><br /><en-media type="image/png" hash="9dd56bb46418bfd57a2e6db311f26d4b" /><br /><en-media type="image/png" hash="4869bfb061e56691e34a9ce85ce65f40" /><br /><en-media type="image/jpeg" hash="f91989a3ea326fabb01604261d4a6b0a" /><br /><en-media type="image/jpeg" hash="64e790f91cdabf4056e8905280d475f1" /><br /><en-media type="image/png" hash="3c35039419107dc4bd684454d29bd0cc" /><br /><en-media type="image/png" hash="218d155be22857e24220d2510da279da" /><br /><en-media type="image/png" hash="0e768d6820d7669546f2ab6afc1bd393" /><br /><en-media type="image/png" hash="634bc5f4039a144cbcbcf6fcd833129d" /><div><br /></div></en-note>', contentHash=b'\x1a\x12\xba\xed\x11/\xec1\x9c\xf1\xb2\xaazM\xbd\xd2', contentLength=991, created=1576292185000, updated=1576294481000, deleted=None, active=True, updateSequenceNum=75, notebookGuid='b396fe72-a1f7-44e3-acac-84f3b55717a7', tagGuids=None, resources=[Resource(guid='67a57dc2-43ba-4142-a3fa-154a55ec885d', noteGuid='f3028259-c103-441f-b33a-df6148e7a79f', data=Data(bodyHash=b'\x0ev\x8dh \xd7f\x95F\xf2\xabj\xfc\x1b\xd3\x93', size=69889, body=b'\xff\xd8\xff ... xd9'), mime='image/png', width=None, height=None, duration=None, active=True, recognition=None, attributes=ResourceAttributes(sourceURL=None, timestamp=None, latitude=None, longitude=None, altitude=None, cameraMake=None, cameraModel=None, clientWillIndex=None, recoType=None, fileName='xiaomi9_vertical_partial.png', attachment=None, applicationData=None), updateSequenceNum=73, alternateData=None)], attributes=NoteAttributes(subjectDate=None, latitude=None, longitude=None, altitude=None, author='wasteg', source=None, sourceURL=None, sourceApplication=None, shareDate=None, reminderOrder=None, reminderDoneTime=None, reminderTime=None, placeName=None, contentClass=None, applicationData=None, lastEditedBy=None, classifications=None, creatorId=None, lastEditorId=None), tagNames=None)
可以看到,其中有多个图片
- <en-media type=”image/png” hash=”0ef4433ff1b0fbe0778f26ab003287c3″ />
然后也可以看到note变量有resources的列表