-
-
Save sooop/98b58f165692f7ea39bb to your computer and use it in GitHub Desktop.
Send current view content to w/add (POST)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[{ | |
"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