#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. 关于UIView的hitTest:withEvent:方法的理解

    闲来无事 观摩别人的项目 常常发现对UIView的hitTest:withEvent:方法的重写,以前也查过这个方法的用法作用,但是时间一长又忘记了.今天再次看到,就记录一下. 用户触摸屏幕后事件的传 ...

  2. vue介绍和简单使用

    Vue是什么? Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅易 ...

  3. Android系统移植与调试之------->如何修改Android设备的默认休眠时间

    1.找到~/mx0831-0525/frameworks/base/packages/SettingsProvider/res/values/ defaults.xml文件 2.修改默认休眠时间 3. ...

  4. The path "fos_user.from_email.address" cannot contain an empty value, but got null.

    The path "fos_user.from_email.address" cannot contain an empty value, but got null.. 修改 pa ...

  5. linux 10 -Bash Shell编程

    二十三. Bash Shell编程:     1.  读取用户变量:     read命令是用于从终端或者文件中读取输入的内建命令,read命令读取整行输入,每行末尾的换行符不被读入.在read命令后 ...

  6. mysql存储引擎(待补充)

    数据库中的表也应该有不同的类型,表的类型不同,会对应mysql不同的存取机制,表类型又称为存储引擎 存储引擎说白了就是如何存取数据.如何为存储的数据建立索引和如何更新.查询数据等技术的实现方法.因为在 ...

  7. rails跨域请求配置

    gem 'rack-cors', '~> 0.3.1'application.rb config.middleware.insert_before 0, "Rack::Cors&quo ...

  8. Android Media应用开发

    Java层API : AudioRecord 采集音频(PCM格式)AudioTrack 播放音频 Camera 用来采集摄像头的数据Surface / SurfaceView / GLSurface ...

  9. Data Structure Binary Tree: Iterative Postorder Traversal

    http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...

  10. 0424 collections模块、time模块、rondom模块、sys模块

    昨日回顾:hashlib 摘要 md5 sha系列 文件的一致性校验 密文的认证 logging 记录日志 两种用法 basicConfig不常用 getLogger()常用 可以通过一个参数去控制全 ...