Skip to content

Instantly share code, notes, and snippets.

@sooop

sooop/Send2W.py Secret

Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sooop/98b58f165692f7ea39bb to your computer and use it in GitHub Desktop.
Save sooop/98b58f165692f7ea39bb to your computer and use it in GitHub Desktop.
Send current view content to w/add (POST)
import sublime, sublime_plugin
# !!! Python3's xmlrpc is move to xmlrpc.client module
import urllib
class SendWsCommand(sublime_plugin.TextCommand):
def run(self, edit):
print('aa')
self.buffer_text = self.view.substr(
sublime.Region(0, self.view.size()))
self.get_title()
def get_title(self):
self.view.window().show_input_panel("title: ", "",
self.send, None, None)
def send(self, keyword):
print("*" * 15)
data = [
('title', keyword),
('keyword', keyword),
('content', self.buffer_text)
]
encoded_data = urllib.parse.urlencode(data).encode('utf-8')
headers = {
'Content-type': 'application/x-www-form-urlencoded',
'Accept': 'text/html',
}
request = urllib.request.Request('http://w/add',
data = encoded_data,
headers=headers,
method='POST')
response = urllib.request.urlopen(request)
return response.read()
[{
"caption": "Send Text To W",
"command": "send_ws"
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment