Skip to content

Instantly share code, notes, and snippets.

@prepor
Last active August 29, 2015 14:03
Show Gist options
  • Save prepor/e1e00373866b7b54d273 to your computer and use it in GitHub Desktop.
Save prepor/e1e00373866b7b54d273 to your computer and use it in GitHub Desktop.
Alfred workflow for refheap.com
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