#! /usr/bin/python3 from argparse import ArgumentParser import os import sys from urllib.parse import urljoin import requests paste_host = 'paste.ubuntu.com' paste_path = '' if __name__ == '__main__': poster = os.environ.get("USER") parser = ArgumentParser() parser.add_argument("-f", "--format", default="text", help="format of paste") parser.add_argument("title", default="The loser %s didn't even add a title" % poster, nargs="?") args = parser.parse_args() form = (('poster', poster), ('title', args.title), ('syntax', args.format), ('content', sys.stdin.read())) response = requests.post('https://%s/%s' % (paste_host, paste_path.lstrip('/')), data=form, allow_redirects=False) location = response.headers['Location'] if location: print(urljoin('https://' + paste_host, location)) else: print('Unexpected response:\n%s' % response.headers)