Skip to content

Instantly share code, notes, and snippets.

@meunierd
Created January 24, 2012 05:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save meunierd/1668147 to your computer and use it in GitHub Desktop.
Save meunierd/1668147 to your computer and use it in GitHub Desktop.
Hastebin Python Client
#!/usr/bin/env python
"""
Usage:
$ cat hastebin.py | ./hastebin.py
http://hastebin.com/KEY
$ ./hastebin.py hastebin.py
http://hastebin.com/KEY
"""
import json, requests, sys
URL = "http://hastebin.com"
if sys.stdin.isatty():
with open(sys.argv[1], 'r') as filedata:
data = "".join(filedata.readlines()).strip()
else:
data = "".join(sys.stdin.readlines()).strip()
response = requests.post(URL + "/documents", data)
sys.stdout.write("%s/%s\n" % (URL, json.loads(response.text)['key']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment