chiark / gitweb /
bugzilla-show: use HTTPS; drop warthogs and ubuntu
[bin.git] / ubuntu-paste
1 #! /usr/bin/python3
2
3 from argparse import ArgumentParser
4 import os
5 import sys
6 from urllib.parse import urljoin
7
8 import requests
9
10
11 paste_host = 'paste.ubuntu.com'
12 paste_path = ''
13
14
15 if __name__ == '__main__':
16     poster = os.environ.get("USER")
17
18     parser = ArgumentParser()
19     parser.add_argument("-f", "--format", default="text", help="format of paste")
20     parser.add_argument("title", default="The loser %s didn't even add a title" % poster, nargs="?")
21     args = parser.parse_args()
22
23     form = (('poster', poster), ('title', args.title), ('syntax', args.format), ('content', sys.stdin.read()))
24     response = requests.post('https://%s/%s' % (paste_host, paste_path.lstrip('/')), data=form, allow_redirects=False)
25     location = response.headers['Location']
26     if location:
27         print(urljoin('https://' + paste_host, location))
28     else:
29         print('Unexpected response:\n%s' % response.headers)