1.  
  2. #coding:utf-8
  3. import sys
  4. sys.path.append("lib")
  5. import thrift.protocol.TBinaryProtocol as TBinaryProtocol
  6. import thrift.transport.THttpClient as THttpClient
  7. import evernote.edam.userstore.UserStore as UserStore
  8. import evernote.edam.notestore.NoteStore as NoteStore
  9. import evernote.edam.type.ttypes as Types
  10. import evernote.edam.error.ttypes as Errors
  11. from html import XHTML
  12. import sublime,sublime_plugin
  13.  
  14. consumer_key = 'jamiesun-2467'
  15. consumer_secret ='7794453e92251986'
  16. evernoteHost = "www.evernote.com"
  17. userStoreUri = "https://" + evernoteHost + "/edam/user"
  18.  
  19. settings = sublime.load_settings("SublimeEvernote.sublime-settings")
  20.  
  21. class SendToEvernoteCommand(sublime_plugin.TextCommand):
  22. def __init__(self,view):
  23. self.view = view
  24. self.window = sublime.active_window()
  25.  
  26. def connect(self,callback,**kwargs):
  27. sublime.status_message("authenticate..., please wait...")
  28. def _connect(username,password):
  29. try:
  30. userStoreHttpClient = THttpClient.THttpClient(userStoreUri)
  31. userStoreProtocol = TBinaryProtocol.TBinaryProtocol(userStoreHttpClient)
  32. userStore = UserStore.Client(userStoreProtocol)
  33. authresult = userStore.authenticate(username,password,consumer_key,consumer_secret)
  34. if authresult:
  35. token = authresult.authenticationToken
  36. noteStoreUrl = authresult.noteStoreUrl
  37. if not settings.get("password") and sublime.ok_cancel_dialog("Remember password?"):
  38. settings.set("password",password)
  39. settings.set("username",username)
  40. settings.set("authToken",token)
  41. settings.set("noteStoreUrl",noteStoreUrl)
  42. sublime.save_settings('SublimeEvernote.sublime-settings')
  43. sublime.status_message("authenticate ok")
  44. callback(**kwargs)
  45. else:
  46. raise Exception("authenticate failure")
  47. except Exception,e:
  48. sublime.error_message("error:%s"%e)
  49.  
  50. def on_username(username):
  51. def on_passwd(password):
  52. if username and password:
  53. _connect(username,password)
  54. self.window.show_input_panel("password (required)::","",on_passwd,None,None)
  55.  
  56. iusername = settings.get("username")
  57. ipassword = settings.get("password")
  58. if not iusername or not ipassword:
  59. self.window.show_input_panel("username (required)::","",on_username,None,None)
  60. else:
  61. _connect(iusername,ipassword)
  62.  
  63. def send_note(self,**kwargs):
  64. authToken = settings.get("authToken")
  65. noteStoreUrl = settings.get('noteStoreUrl')
  66. noteStoreHttpClient = THttpClient.THttpClient(noteStoreUrl)
  67. noteStoreProtocol = TBinaryProtocol.TBinaryProtocol(noteStoreHttpClient)
  68. noteStore = NoteStore.Client(noteStoreProtocol)
  69. region = sublime.Region(0L, self.view.size())
  70. content = self.view.substr(region)
  71.  
  72. def sendnote(title,tags):
  73. xh = XHTML()
  74. note = Types.Note()
  75. note.title = title.encode('utf-8')
  76. note.content = '<?xml version="1.0" encoding="UTF-8"?>'
  77. note.content += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
  78. note.content += '<en-note><pre>%s'%xh.p(content.encode('utf-8'))
  79. note.content += '</pre></en-note>'
  80. note.tagNames = tags and tags.split(",") or []
  81.  
  82. #set note's parent notebook guid
  83. note.notebookGuid = "eeb43022-0fd4-4c29-894b-03e3d5fa2f45"
  84.  
  85. try:
  86. sublime.status_message("please wait...")
  87. cnote = noteStore.createNote(authToken, note)
  88. sublime.status_message("send success guid:%s"%cnote.guid)
  89. sublime.message_dialog("success")
  90. except Errors.EDAMUserException,e:
  91. args = dict(title=title,tags=tags)
  92. if e.errorCode == 9:
  93. self.connect(self.send_note,**args)
  94. else:
  95. if sublime.ok_cancel_dialog('error %s! retry?'%e):
  96. self.connect(self.send_note,**args)
  97. except Exception,e:
  98. sublime.error_message('error %s'%e)
  99.  
  100. def on_title(title):
  101. def on_tags(tags):
  102. sendnote(title,tags)
  103. self.window.show_input_panel("Tags (Optional)::","",on_tags,None,None)
  104.  
  105. if not kwargs.get("title"):
  106. self.window.show_input_panel("Title (required)::","",on_title,None,None)
  107. else:
  108. sendnote(kwargs.get("title"),kwargs.get("tags"))
  109.  
  110. def run(self, edit):
  111. if not settings.get("authToken"):
  112. self.connect(self.send_note)
  113. else:
  114. 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. can not find java.util.map java.lang.Double问题

    mybatis      @Param注解和ParamType属性不能共存

  2. Django APP之contenttypes简单应用

    Conttenttypes介绍 当你看到contenttype你是不是想到了请求头的contenttype? 但是 此contenttypes不是请求头Content-Type而是Django自带的a ...

  3. matlab + c/c++ opencv 混合编程

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...

  4. composer 更新国内镜像地址

    composer config -g repo.packagist composer https://packagist.phpcomposer.com​

  5. 使用MapReduce将HDFS数据导入Mysql

    使用MapReduce将Mysql数据导入HDFS代码链接 将HDFS数据导入Mysql,代码示例 package com.zhen.mysqlToHDFS; import java.io.DataI ...

  6. SpringMVC注解示例

    1.web.xml <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-cla ...

  7. 自定义响应结构 AjaxResult()

    package com.dsj.gdbd.utils.ajax; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxm ...

  8. css中单位px和em,rem的区别

    PX:PX实际上就是像素,用PX设置字体大小时,比较稳定和精确.但是这种方法存在一个问题,当用户在浏览器中浏览我们制作的Web页面时,如果改变了浏览器的缩放,这时会使用我们的Web页面布局被打破.这样 ...

  9. 我理解的关于Vue.nextTick()的正确使用

    什么是Vue.nextTick() 官方文档解释如下: 在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 我理解的官方文档的这句话的侧重点在最后那半 ...

  10. js 定义hash类

    // JavaScript Documentfunction HashTable(){    this._hash={};    this._count=0;            /**    *添 ...