Last active
August 29, 2015 14:03
-
-
Save prepor/e1e00373866b7b54d273 to your computer and use it in GitHub Desktop.
Alfred workflow for refheap.com
This file contains hidden or 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 subprocess, urllib, json, sys | |
| from subprocess import Popen, PIPE, STDOUT | |
| def pbcopy(txt): | |
| p = Popen(['pbcopy'], stdout=PIPE, stdin=PIPE, stderr=STDOUT) | |
| p.communicate(txt)[0] | |
| my_env = {} | |
| my_env['LANG'] = 'en_US.UTF-8' | |
| username = "*****" | |
| token = "******************" | |
| content = subprocess.check_output("pbpaste", env=my_env) | |
| body = {'contents': content, | |
| 'token': token, | |
| 'private': "true", | |
| 'username': username} | |
| lang = '{query}' | |
| if len(lang) > 0: | |
| body['language'] = lang | |
| res = urllib.urlopen("https://www.refheap.com/api/paste", urllib.urlencode(body)) | |
| if res.getcode() == 201: | |
| data = json.loads(res.read()) | |
| url = data['url'] + "/fullscreen" | |
| #pbcopy(url) | |
| print url | |
| else: | |
| sys.exit(res.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment