#coding:utf-8
import sys
sys.path.append("lib")
import thrift.protocol.TBinaryProtocol as TBinaryProtocol
import thrift.transport.THttpClient as THttpClient
import evernote.edam.userstore.UserStore as UserStore
import evernote.edam.notestore.NoteStore as NoteStore
import evernote.edam.type.ttypes as Types
import evernote.edam.error.ttypes as Errors
from html import XHTML
import sublime,sublime_plugin consumer_key = 'jamiesun-2467'
consumer_secret ='7794453e92251986'
evernoteHost = "www.evernote.com"
userStoreUri = "https://" + evernoteHost + "/edam/user" settings = sublime.load_settings("SublimeEvernote.sublime-settings") class SendToEvernoteCommand(sublime_plugin.TextCommand):
def __init__(self,view):
self.view = view
self.window = sublime.active_window() def connect(self,callback,**kwargs):
sublime.status_message("authenticate..., please wait...")
def _connect(username,password):
try:
userStoreHttpClient = THttpClient.THttpClient(userStoreUri)
userStoreProtocol = TBinaryProtocol.TBinaryProtocol(userStoreHttpClient)
userStore = UserStore.Client(userStoreProtocol)
authresult = userStore.authenticate(username,password,consumer_key,consumer_secret)
if authresult:
token = authresult.authenticationToken
noteStoreUrl = authresult.noteStoreUrl
if not settings.get("password") and sublime.ok_cancel_dialog("Remember password?"):
settings.set("password",password)
settings.set("username",username)
settings.set("authToken",token)
settings.set("noteStoreUrl",noteStoreUrl)
sublime.save_settings('SublimeEvernote.sublime-settings')
sublime.status_message("authenticate ok")
callback(**kwargs)
else:
raise Exception("authenticate failure")
except Exception,e:
sublime.error_message("error:%s"%e) def on_username(username):
def on_passwd(password):
if username and password:
_connect(username,password)
self.window.show_input_panel("password (required)::","",on_passwd,None,None) iusername = settings.get("username")
ipassword = settings.get("password")
if not iusername or not ipassword:
self.window.show_input_panel("username (required)::","",on_username,None,None)
else:
_connect(iusername,ipassword) def send_note(self,**kwargs):
authToken = settings.get("authToken")
noteStoreUrl = settings.get('noteStoreUrl')
noteStoreHttpClient = THttpClient.THttpClient(noteStoreUrl)
noteStoreProtocol = TBinaryProtocol.TBinaryProtocol(noteStoreHttpClient)
noteStore = NoteStore.Client(noteStoreProtocol)
region = sublime.Region(0L, self.view.size())
content = self.view.substr(region) def sendnote(title,tags):
xh = XHTML()
note = Types.Note()
note.title = title.encode('utf-8')
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><pre>%s'%xh.p(content.encode('utf-8'))
note.content += '</pre></en-note>'
note.tagNames = tags and tags.split(",") or [] #set note's parent notebook guid
note.notebookGuid = "eeb43022-0fd4-4c29-894b-03e3d5fa2f45" try:
sublime.status_message("please wait...")
cnote = noteStore.createNote(authToken, note)
sublime.status_message("send success guid:%s"%cnote.guid)
sublime.message_dialog("success")
except Errors.EDAMUserException,e:
args = dict(title=title,tags=tags)
if e.errorCode == 9:
self.connect(self.send_note,**args)
else:
if sublime.ok_cancel_dialog('error %s! retry?'%e):
self.connect(self.send_note,**args)
except Exception,e:
sublime.error_message('error %s'%e) def on_title(title):
def on_tags(tags):
sendnote(title,tags)
self.window.show_input_panel("Tags (Optional)::","",on_tags,None,None) if not kwargs.get("title"):
self.window.show_input_panel("Title (required)::","",on_title,None,None)
else:
sendnote(kwargs.get("title"),kwargs.get("tags")) def run(self, edit):
if not settings.get("authToken"):
self.connect(self.send_note)
else:
self.send_note()

Send Code to evernote by my specify notebook的更多相关文章

  1. VS Code Python 全新发布!Jupyter Notebook 原生支持终于来了!

    VS Code Python 全新发布!Jupyter Notebook 原生支持终于来了! 北京时间 2019 年 10 月 9 日,微软发布了全新的 VS Code Python 插件,带来了众多 ...

  2. VS Code 之 Jupyter NoteBook 初试

    一.前言 在今年九月的 PyCon China 大会上,官宣了一项 VS Code Python 的全新功能:Visual Studio Code Python 插件将提供 Jupyter Noteb ...

  3. 使用jupyterthemes插件定制jupyter notebook界面

    jupyter notebook界面是可以定制的,定制位置在:C:\anaconda\Lib\site-packages\notebook\static\custom. 启动jupyter noteb ...

  4. 官宣!VS Code Python 全新功能在 PyCon China 全球首发!

    北京时间 2019 年 9 月 21 日,PyCon China 2019 在上海举行. 在下午的演讲中,来自微软开发工具事业部的资深研发工程师 在演讲中,我们看到了 Azure Notebook 与 ...

  5. Code Book All In One

    Code Book All In One Jupyter Notebook Jupyter Lab https://jupyter.org/ Storybook https://storybook.j ...

  6. jQuery源码 Ajax模块分析

    写在前面: 先讲讲ajax中的相关函数,然后结合函数功能来具体分析源代码. 相关函数: >>ajax全局事件处理程序 .ajaxStart(handler) 注册一个ajaxStart事件 ...

  7. 利用nodejs实现登录并转码视频(原创)

    nodejs的出现让前端人员可以使用js打造后台,也许哪天就真的摆脱了对java或者php的依赖了. 今天跟大家分享一个利用nodejs接受前端post请求,并实现视频转码的这样一个例子.视频转码用到 ...

  8. nodejs学习笔记二——链接mongodb

    a.安装mongoose库用来链接mongodb数据库 安装mongodb数据库参考mongodb安装 前言(怨言) 本来是想安装mongodb库来链接mongodb的,命令行到nodejs工程目录: ...

  9. loopback 05

    数据并发处理 数据库事务 事务隔离 ACID性质 原子性(Atomicity): 要么全部被执行,要么都不执行; 一致性(Consistency): 满足完整性约束; 隔离性(Isolation): ...

随机推荐

  1. Java中List.remove报UnsupportedOperationException异常

    今天项目中有个需求场景: A和B都是List,而B是A的子集,现在想求A和B的差集. 想到了List中提供的removeAll()方法可以求得差集,但是结果确报了UnsupportedOperatio ...

  2. 【python】-- 类的继承(新式类/经典类)、多态

    继承 之前我们说到了类的公有属性和类的私有属性,其实就是类的封装,现在准备随笔的 是继承,是面向对象的第二大特性. 面向对象编程 (OOP) 语言的一个主要功能就是“继承”.继承是指这样一种能力:它可 ...

  3. TCP协议要点和难点全解

    转载自http://www.cnblogs.com/leetieniu2014/p/5771324.html TCP协议要点和难点全解 说明: 1).本文以TCP的发展历程解析容易引起混淆,误会的方方 ...

  4. hibernate 多对多操作(级联操作)

    一.级联保存 分别在用户和角色配置文件中在set标签中加入cascade="save-update": 示例:添加同时添加用户对象和角色对象并关联两个对象: 只需将角色放入用户对象 ...

  5. Write 语句

    ABAP Write 语句 转载▼http://blog.sina.com.cn/s/blog_5ccd375b0100ghhi.html   1.Write 叙述 ABAP/4 用来在屏幕上输出数据 ...

  6. Broadcast Intent & Broadcast Receiver

    当Android系统发生某种状况,必须通知所有程序进行处理时,例如电量不足等,可利用Broadcast Intent对象的功能来进行信息广播. 运行机制包括两部:送出Intent对象的程序:监听广播信 ...

  7. 使用django开发一个博客

    环境: MAC 10.10.5  Yosemite Python 3.73 Django 代码托管 github

  8. Git——版本控制概论(一)

    随着信息技术的发展,软件开发已不是小手工作坊,软件的规模和复杂度已经不再适合一个人单打独斗的开发了, 团队协作变得相当重要,如果没有VCS(版本控制系统Version Control System), ...

  9. 教你如何写一个 Yii2 扩展

    前言 把一系列相关联的功能使用模块开发,好处多多,维护起来很方便,模块还可以单独发布出去,让下一个项目之间使用,真是方便. 下面我就写一个开发扩展的简单教程. Gii gii 自带帮助我们生成一个基本 ...

  10. SQL语法结构

    目录 一.增 1.增加字段 2.新建约束 二.删 1.删除字段 2.删除约束 三.改 1.修改字段 一.增 1.增加字段: ALTER TABLE [表名] ADD [字段名] NVARCHAR () ...