Created
May 28, 2014 11:50
-
-
Save cdunklau/cf87313173622c84bd81 to your computer and use it in GitHub Desktop.
Pastebin a file to bpaste.net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import requests | |
SPACEPASTE_URL = 'http://bpaste.net/' | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'file', | |
metavar='FILE', | |
help="The file to upload", | |
) | |
parser.add_argument( | |
'-l', '--lang', | |
metavar='LANGUAGE', | |
default=None, | |
help="The language to use for highlighting", | |
) | |
ext_to_lang = { | |
'py': 'python', | |
'txt': 'text', | |
} | |
def main(): | |
args = parser.parse_args() | |
fname = args.file | |
with open(fname) as fp: | |
text = fp.read() | |
if args.lang is None: | |
lang = ext_to_lang.get(fname.rsplit('.', 1)[-1], 'text') | |
else: | |
lang = ext_to_lang.get(args.lang, 'text') | |
data = { | |
'code': text, | |
'language': lang, | |
'webpage': '', | |
'private': 'on', | |
} | |
resp = requests.post(SPACEPASTE_URL, data=data) | |
resp.raise_for_status() | |
print resp.url | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment