Skip to content

Instantly share code, notes, and snippets.

@sooop

sooop/Send2W.py Secret

Last active Aug 29, 2015
Embed
What would you like to do?
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