id: 53be46e584c4418fb3a8d28747dbc7b6
parent_id: 
item_type: 1
item_id: eaa9d0f77545423882953ca8d30a9678
item_updated_time: 1764345489790
title_diff: "[{\"diffs\":[[1,\"用印象笔记的Python SDK接口开发个自用小工具\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":26}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>用印象笔记的Python SDK接口开发个自用小工具</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"20702\\\"></a>\\\r\\\n<h1>用印象笔记的Python SDK接口开发个自用小工具</h1>\\\r\\\n\\\r\\\n<div><span>\\\n  <div>\\\n<div><br/></div><div style=\\\"font-size: 16px; display:block; min-width: 100%;\\\"> <div style=\\\"background-color:transparent;font:inherit;vertical-align:baseline;\\\"><div style=\\\"background-color:transparent;font:inherit;vertical-align:baseline;font-family:&quot;PT Serif&quot;;font-size:16px;line-height:1.5em;color:rgb(31, 9, 9);text-align:left;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;z-index:200;padding-left:2em;padding-right:2em;margin-left:auto;margin-right:auto;position:relative;width:36em;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;position:relative;margin-left:-25px;margin-right:25px;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;position:relative;padding-top:0px;padding-bottom:9em;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;position:relative;margin-bottom:0px;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\"><h1 style=\\\"border:0px;font:inherit;vertical-align:baseline;font-family:&quot;PT Serif&quot;;text-align:left;font-size:35px;font-weight:normal;line-height:35px;margin-bottom:20px;padding:0px;margin:0px;\\\">用印象笔记的Python SDK接口开发个自用小工具</h1><div style=\\\"padding:0px;border:0px;font:inherit;vertical-align:baseline;position:relative;height:1em;line-height:1;text-align:center;padding-top:1.5em;padding-bottom:1.5em;margin:0px;margin-bottom:0px;\\\"><div style=\\\"padding:0px;border:0px;font:inherit;vertical-align:baseline;position:absolute;left:-4em;top:50%;z-index:10;width:100%;padding-left:4em;padding-right:4em;height:0.1em;opacity:0.5;background:-webkit-linear-gradient(0deg, rgb(243, 242, 238) 1%, rgb(31, 9, 9) 50%, rgb(243, 242, 238) 99%);margin:0px;margin-bottom:0px;\\\"><span style=\\\"font:inherit;position:absolute;left:-4em;top:50%;z-index:10;width:100%;padding-left:4em;padding-right:4em;height:0.1em;margin:0px;opacity:0.5;background:-webkit-linear-gradient(0deg, rgb(243, 242, 238) 1%, rgb(31, 9, 9) 50%, rgb(243, 242, 238) 99%);\\\"></span></div></div></div>\\\n\\\n        \\\n        <div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">\\\n                    <div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">\\\n            <a href=\\\"https://www.jianshu.com/u/rFtdjp\\\" style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(6, 85, 136);text-decoration:none;\\\" target=\\\"_blank\\\">向阳乔木</a>\\\n            \\\n            <a style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(6, 85, 136);text-decoration:none;\\\" target=\\\"_blank\\\">关注</a>\\\n            \\\n            <div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">\\\n              \\\n              \\\n                2017.11.13 19:11*\\\n              字数 651\\\n            阅读 137评论 0喜欢 1</div>\\\n          </div>\\\n          \\\n        </div>\\\n\\\n\\\n        \\\n        <div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">\\\n          <div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">\\\n            <p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">去年写过一篇文章：<a href=\\\"https://link.jianshu.com/?t=https://zhuanlan.zhihu.com/p/24545638?utm_source=itdadao&amp;utm_medium=referral\\\" style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(6, 85, 136);text-decoration:none;\\\" target=\\\"_blank\\\">https://zhuanlan.zhihu.com/p/24545638?utm_source=itdadao&amp;utm_medium=referral</a></p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">其中分享了如何用印象笔记的开发者接口，用php开发一个收集金句的小工具。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">今年换了Macbook，之前的环境和工具都没了，于是使用Python3从头写了一个同样的工具。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">首先，因为印象笔记官方只提供Python2的SDK，所以去Github下载非官方的Python3 SDK。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">下载地址：<a href=\\\"https://link.jianshu.com/?t=https://github.com/evernote/evernote-sdk-python3\\\" style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(6, 85, 136);text-decoration:none;\\\" target=\\\"_blank\\\">https://github.com/evernote/evernote-sdk-python3</a></p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">点击绿色的Clone or Download按钮，然后选择Download ZIP。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">解压后打开sample文件夹，然后再进入client文件夹，其中有个文件名叫EDAMTest.py</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">复制一份改名为yinxiang.py</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">在这个文件基础上进行修改，开发属于自己的工具，代码如下。</p>\\\n<pre style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;background-color:rgb(243, 242, 238);font-family:Inconsolata;width:auto;font-size:0.875em;line-height:1.71429em;\\\"><code style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;font-family:Inconsolata;line-height:1.71429em;font-size:1.15em;\\\"># coding = utf-8\\\nimport hashlib\\\nimport binascii\\\nimport evernote.edam.userstore.constants as UserStoreConstants\\\nimport evernote.edam.type.ttypes as Types\\\nimport os\\\nimport time\\\nimport re\\\nfrom evernote.api.client import EvernoteClient\\\nfrom evernote.edam.notestore.ttypes import NoteFilter\\\nfrom evernote.edam.type.ttypes import NoteSortOrder\\\n\\\n# auth_token申请地址：https://dev.yinxiang.com/doc/articles/dev_tokens.php\\\nauth_token = &quot;S=s3:U=1d3c1:E=16081a4df70:C=15929f3b2d0:P=1cd:A=en-devtoken:V=2:H=f540d0359f7e0d5c52235eb1c19c9885&quot;\\\n\\\n# 关掉沙盒模式\\\nsandbox = False\\\n# True代表使用的国内的印象笔记，而不是Evernote国际版\\\nchina = True\\\n\\\n# 创建一个印象笔记client对象\\\nclient = EvernoteClient(token = auth_token, sandbox = sandbox, china = china)\\\n\\\n# user_store = client.get_user_store()\\\n# 通过client对象获取note_store对象\\\nnote_store = client.get_note_store()\\\n\\\n# 下面代码为了获取所有的笔记本数量、笔记本名和对应的GUID，目前是注释状态，为了找到对应的笔记本GUID\\\n# notebooks = note_store.listNotebooks()\\\n# print(&quot;Found&quot;, len(notebooks), &quot; notebooks:&quot;)\\\n# for notebook in notebooks:\\\n#     print(notebook.name, notebook.guid)\\\n\\\n# 生成笔记标题，格式例如：20171113阅读记录\\\ndaily_title = time.strftime('%Y%m%d',time.localtime()) + &quot;阅读记录&quot;\\\n\\\n# 生成查找笔记的规则，使用笔记创建排序，指定笔记本GUID，使用标题名搜索\\\nupdated_filter = NoteFilter(order=NoteSortOrder.CREATED, notebookGuid=&quot;9e965c09-5045-4909-ad78-bf95a5bbc09d&quot;, words=daily_title)\\\n# 偏移0\\\noffset = 0\\\n# 只取一条笔记\\\nmax_notes = 1\\\n\\\n# 查找出符合条件的笔记\\\nresult_list = note_store.findNotes(updated_filter, offset, max_notes)\\\n\\\n# 如何找到对应笔记则，在这个笔记里加一条金句，否则创建一条新笔记把金句加进去\\\nif result_list.totalNotes:\\\n    \\\n    # 获取找到笔记的GUID\\\n    note_guid = result_list.notes[0].guid\\\n    # 获取到对应笔记\\\n    note = note_store.getNote(note_guid,1,1,1,1)\\\n    # 使用正则匹配出笔记里的内容文本\\\n    match_res = re.search(r'&lt;en-note&gt;(.*)&lt;\\\\/en-note&gt;', note.content, re.M|re.I)\\\n    # 如果能匹配到内容，则获取内容设置变量名为old_content，否则old_content为空\\\n    if match_res:\\\n        old_content = match_res.group(1)\\\n    else:\\\n        old_content = &quot;&quot;\\\n    \\\n    # 读取Mac系统tmp文件夹下的evernote.txt里的内容，使用utf-8编码\\\n    newline = open('/tmp/evernote.txt','r', encoding='utf-8').read()\\\n\\\n\\\n    # 构建待更新的笔记内容\\\n    note.content = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;'\\\n    note.content += '&lt;!DOCTYPE en-note SYSTEM ' \\\\\\\n                    '&quot;http://xml.evernote.com/pub/enml2.dtd&quot;&gt;'\\\n    note.content += '&lt;en-note&gt;' + old_content +'&lt;br/&gt;' + newline\\\n\\\n    note.content += '&lt;/en-note&gt;'\\\n    # 更新找到的旧笔记内容，把新的金句加进去。\\\n    res = note_store.updateNote(auth_token, note)\\\n# 没有找到旧的笔记，则新建一个使用今天日期+阅读记录为名字的新笔记\\\nelse:\\\n    # 创建note对象\\\n    note = Types.Note() \\\n    # 设置笔记名称 \\\n    note.title = daily_title \\\n    # 读取evenote.txt里的内容\\\n    words = open('/tmp/evernote.txt','r',encoding='utf-8').read() + '&lt;br/&gt;'\\\n\\\n    # 构建note的内容，把句子加到&lt;en-note&gt;标签中\\\n\\\n    note.content = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;'\\\n    note.content += '&lt;!DOCTYPE en-note SYSTEM ' \\\\\\\n                    '&quot;http://xml.evernote.com/pub/enml2.dtd&quot;&gt;'\\\n    note.content += '&lt;en-note&gt;' + words\\\n    note.content += '&lt;/en-note&gt;'\\\n\\\n    # 指定笔记本GUID\\\n    note.notebookGuid = &quot;9e965c09-5045-4909-ad78-bf95a5bbc09d&quot;\\\n    # 创建笔记\\\n    created_note = note_store.createNote(note)\\\n    # 打印创建好的笔记标题和GUID\\\n    print(note.title + &quot;创建成功，GUID： &quot;, created_note.guid)\\\n\\\n</code></pre>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">在以上内容完成后，打开Automator工具，新建一个服务，然后点击资源库-&gt;实用工具-&gt;运行 Shell脚本（双击）</p>\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">\\\n\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;display:block;text-align:center;margin-top:1em;margin-bottom:0px;\\\"><img src=\\\":/ce4dba79b0be468d91a6ceb0457ead32\\\" type=\\\"image/jpeg\\\" data-filename=\\\"1537-24755429855cd25f.jpg\\\" height=\\\"386\\\" style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;border-color:rgb(31, 9, 9);display:block;max-width:100%;\\\" width=\\\"576\\\"/></div></div>\\\n</div>\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">15105707054299.jpg</div>\\\n</div>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">先解释下第一行<br/>\\\n<code style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;font-family:Inconsolata;font-size:0.875em;line-height:1.71429em;\\\">export PYTHONPATH=/Users/joe/Documents/codelife/python/evernote_py3/lib</code></p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">这句为了指定python3印象笔记的SDK环境变量，否则命令行可以运行，但在automator里不行，会提示找不到对应的evenote模块。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\"><code style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;font-family:Inconsolata;font-size:0.875em;line-height:1.71429em;\\\">LANG=en_US.UTF-8 pbpaste -txt &gt; /tmp/evernote.txt</code></p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">请注意，LANG=en_US.UTF-8 很重要，否则会造成乱码。<br/>\\\npbpaste是Linux类系统自带的命令，可以读取剪贴板里的数据。然后使用 “&gt; /tmp/evernote.txt” 在/tmp目录下输入生成一个叫做evernote.txt的文件。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">整个脚本的意思是：</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">先把剪贴板里的内容存入临时文件夹下的evernote.txt文件中，然后用Python3主文件去执行yinxiang.py 这个文件写入印象笔记中。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">对应的Python3主文件地址在命令行下使用 which python3查询。</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">整体代码如下，请对应修改自己的环境变量地址、python3文件地址和代码地址。</p>\\\n<pre style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;background-color:rgb(243, 242, 238);font-family:Inconsolata;width:auto;font-size:0.875em;line-height:1.71429em;\\\"><code style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;font-family:Inconsolata;line-height:1.71429em;font-size:1.15em;\\\">export PYTHONPATH=/Users/joe/Documents/codelife/python/evernote_py3/lib\\\nLANG=en_US.UTF-8 pbpaste -txt &gt; /tmp/evernote.txt  &amp; /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 /Users/joe/Documents/codelife/python/evernote_py3/sample/client/yinxiang.py\\\n\\\n</code></pre>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">然后保存文件名为save2evenote</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">然后打开“系统偏好设置”-&gt;“键盘”-&gt;“快捷键”-&gt;&quot;服务&quot;</p>\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">\\\n\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\"><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;display:block;text-align:center;margin-top:1em;margin-bottom:0px;\\\"><img src=\\\":/d59624625ddb4b6e89841913173bd097\\\" type=\\\"image/jpeg\\\" data-filename=\\\"1537-e8481ef67819de92.jpg\\\" height=\\\"507\\\" style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;border-color:rgb(31, 9, 9);display:block;max-width:100%;\\\" width=\\\"576\\\"/></div></div>\\\n</div>\\\n<div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">15105712578089.jpg</div>\\\n</div>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;\\\">这时你会发现有一个你刚才保存的服务会出现在这里，然后给它设置个快捷键，比如Ctrl+ALt+Command+V</p>\\\n<p style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:0px;\\\">至此，终于一切都搞定了，以后遇到好段落和句子，只需要选中按下Command+C，然后再按 Ctrl+ALt+Command+V 就自动贴到印象笔记了。</p>\\\n\\\n          </div>\\\n        </div>\\\n    </div></div></div><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;margin-bottom:1.5em;position:absolute;top:-1000px;left:-1000px;\\\">Measure</div><div style=\\\"margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;position:absolute;top:-1000px;left:-1000px;line-height:1;margin-bottom:0px;\\\">Measure</div></div></div></div></div></div></div></div>\\\n</div>\\\n</span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":14897}]"
metadata_diff: {"new":{"id":"eaa9d0f77545423882953ca8d30a9678","parent_id":"061de1401cfc4cfaadf6e74e015970e9","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764345887264,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T16:20:26.203Z
created_time: 2025-11-28T16:20:26.203Z
type_: 13