summarylogtreecommitdiffstats
path: root/hastebin
diff options
context:
space:
mode:
authorKevin Morris2017-07-17 16:56:55 -0700
committerKevin Morris2017-07-17 16:56:55 -0700
commit51a7ebb8109737aaf8b3f62892d5f16770d6fb18 (patch)
tree185a9cf71b5e631028d65dd69c405208b7774005 /hastebin
downloadaur-51a7ebb8109737aaf8b3f62892d5f16770d6fb18.tar.gz
Initial commit
Signed-off-by: Kevin Morris <kevin.morris@stratodesk.com>
Diffstat (limited to 'hastebin')
-rwxr-xr-xhastebin50
1 files changed, 50 insertions, 0 deletions
diff --git a/hastebin b/hastebin
new file mode 100755
index 00000000000..541fb1e0e7c
--- /dev/null
+++ b/hastebin
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+# -*- coding: UTF-8 -*-
+# Project: hastebin
+# Author: kevr <kevr@nixcode.us>
+# Description: A tool which uploads data from stdin to hastebin.us
+# Copyright (C) 2014 Kevin Morris
+import sys
+import requests
+import json
+from select import select
+
+## Voila hardcoded settings~
+url = "https://hastebin.com"
+timeout = 5 # Change this to any http request timeout you desire
+
+## Immediately timed out select poll
+def has_data(fd):
+ return select([fd], [], [], 0.0) == ([fd], [], [])
+
+def quit(code, msg):
+ print(msg)
+ return code
+
+## Sorry for the C-style functions, I prefer them
+def main():
+ if not has_data(sys.stdin):
+ return quit(1, "hastebin: no data given via stdin")
+
+ try:
+ stdin = sys.stdin.read()
+ except UnicodeDecodeError:
+ return quit(2, "hastebin: an error occured reading stdin")
+
+ response = requests.post("%s/documents" % url, headers={
+ "Accept": "application/json"}, data=stdin)
+ if response.status_code != requests.codes.ok:
+ return quit(3, "hastebin: error submitting POST data to hastebin")
+
+ content = response.content.decode("UTF-8").rstrip()
+ data = json.loads(content)
+
+ print("%s/%s" % (url, data["key"]))
+
+ return 0
+
+# main execution
+if __name__ == "__main__":
+ e = main()
+ exit(e)
+