Skip to content

Instantly share code, notes, and snippets.

@Akasurde
Forked from meunierd/haste.py
Created August 9, 2017 11:41
Show Gist options
  • Save Akasurde/7b5bae894370dbe4f2c42307736ebc14 to your computer and use it in GitHub Desktop.
Save Akasurde/7b5bae894370dbe4f2c42307736ebc14 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