-
Notifications
You must be signed in to change notification settings - Fork 0
/
clbin
executable file
·33 lines (28 loc) · 973 Bytes
/
clbin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3 -W ignore::Warning:urllib3:35
import argparse
import subprocess
import sys
import requests
args_parser = argparse.ArgumentParser()
args_parser.add_argument('-f', '--file', help='file whose contents you want to upload', dest='filename')
args_parser.add_argument('command', nargs=argparse.REMAINDER)
args = args_parser.parse_args()
data = {'clbin': ''}
# Precedence:
# 1) -f file
# 2) command output (stdout and stderr)
# 3) read stdin
try:
if args.filename:
data['clbin'] = open(args.filename).read()
elif args.command:
try:
data['clbin'] = subprocess.check_output(' '.join(args.command), stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
data['clbin'] = e.output
else:
data['clbin'] = sys.stdin.read()
response = requests.post('https://clbin.com/', data)
print(response.content.decode('utf-8').strip())
except KeyboardInterrupt:
pass