phriedrich
By: a guest | Mar 15th, 2010 | Syntax:
Python | Size: 2.33 KB | Hits: 241 | Expires: Never
#!/usr/bin/env python
# coding=UTF-8
# pastebin.py
# writes the input string to pastebin.com and returns the URL
#
# Copyright 2007-2010 Friedrich Preuß <info@phriedrich.de>
# all rights reserved, released under the terms of GPLv2
class pastebin:
def __init__(self):
from getpass import getuser
self.name = getuser()
self.expiry = "1D"
self.format = "Bash"
self.formatTable = {
'Bash' : 8,
'C' : 9,
'C++' : 13,
'CSS' : 16,
'HTML' : 25,
'Java' : 27,
'JavaScript' : 28,
'Lua' : 30,
'None' : 1,
'Perl' : 40,
'PHP' : 41,
'Python' : 42,
'Rails' : 67
}
def send(self, code):
import urllib.request, urllib.parse, urllib.error
try:
format = self.formatTable[self.format.title()]
except:
format = 1
url = 'http://pastebin.com/post.php'
values = {'paste_form' : '/post.php',
'paste_parent_key': '',
'paste_subdomain' : '',
'paste_code' : code,
'paste_format' : format,
'paste_expire_date' : self.expiry.upper(),
'paste_private' : '0',
'paste_name' : self.name,
'paste_email' : '',
'submit' : 'submit'}
data = urllib.parse.urlencode(values)
response = urllib.request.urlopen(url, data)
new_url = response.geturl()
response.close()
return(new_url)
if __name__ == "__main__":
import sys
paste = pastebin()
for arg in sys.argv:
if arg in ("-h", "--help"):
print("Usage: STDOUT | pastebin.py [--name=USERNAME] [--format=FORMAT] [--expiry=(N|10M|1H|1D|1M)]")
sys.exit()
if ("--name") in arg:
paste.name = arg.split('=')[1]
if ("--format") in arg:
paste.format = arg.split('=')[1]
if ("--expiry") in arg:
paste.expiry = arg.split('=')[1]
code = sys.stdin.read()
if code == '':
print("No input data to send …")
sys.exit()
ret_url = paste.send(code)
print(ret_url)