首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在Evernote addNote() (API/Python call)中包含mime类型(JPG、HTML)?

在Evernote的addNote() API/Python调用中包含mime类型(JPG、HTML),可以通过以下步骤实现:

  1. 导入必要的库和模块:
代码语言:txt
复制
import evernote.edam.type.ttypes as Types
import evernote.edam.notestore.ttypes as NoteStoreTypes
import binascii
import mimetypes
  1. 创建一个Note对象,并设置相关属性:
代码语言:txt
复制
note = Types.Note()
note.title = "Note Title"
note.content = '<?xml version="1.0" encoding="UTF-8"?>'
note.content += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
note.content += '<en-note>'

# 添加文本内容
note.content += 'This is the note content.'

# 添加图片附件
image_path = 'path_to_image.jpg'
image_data = open(image_path, 'rb').read()
image_hash = binascii.hexlify(image_data)
image_mime = mimetypes.guess_type(image_path)[0]
image_resource = Types.Resource()
image_resource.mime = image_mime
image_resource.data = Types.Data()
image_resource.data.bodyHash = image_hash
image_resource.data.size = len(image_data)
image_resource.data.body = image_data

note.resources = [image_resource]
note.content += '<en-media type="%s" hash="%s"/>' % (image_mime, image_hash.decode())

# 添加HTML附件
html_path = 'path_to_html.html'
html_data = open(html_path, 'rb').read()
html_hash = binascii.hexlify(html_data)
html_mime = mimetypes.guess_type(html_path)[0]
html_resource = Types.Resource()
html_resource.mime = html_mime
html_resource.data = Types.Data()
html_resource.data.bodyHash = html_hash
html_resource.data.size = len(html_data)
html_resource.data.body = html_data

note.resources.append(html_resource)
note.content += '<en-media type="%s" hash="%s"/>' % (html_mime, html_hash.decode())

note.content += '</en-note>'
  1. 调用Evernote的API方法将Note添加到笔记本中:
代码语言:txt
复制
note_store = client.get_note_store()
note_store.createNote(note)

在上述代码中,首先导入了必要的库和模块。然后创建了一个Note对象,并设置了标题和内容的基本结构。接下来,通过读取图片和HTML文件的数据,并计算其哈希值和MIME类型,创建了对应的资源对象,并将其添加到Note的资源列表中。最后,将资源的MIME类型和哈希值添加到Note的内容中,并调用Evernote的API方法将Note添加到笔记本中。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的沙龙

领券