Created
July 13, 2015 19:00
-
-
Save NoTimeForHero/3e96bf38e43ac303675e to your computer and use it in GitHub Desktop.
Command line pastebin
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/python | |
import sys, os | |
import urllib, urllib2 | |
Highlights = { | |
'bash' : ['*.sh','*.bash'], | |
'php' : ['*.php'], | |
'python' : ['*.python'], | |
'rails' : ['*.rb'], | |
'ruby' : ['Gemfile'], | |
'python' : ['*.py'], | |
'cpp' : ['*.cpp'], | |
'c' : ['*.c'], | |
'yaml' : ['*.yaml'], | |
'ini' : ['*.ini','*.cfg'], | |
'javascript' : ['*.js'], | |
'java' : ['*.java'], | |
'json' : ['*.json'], | |
'dos' : ['*.bat','*.cmd'], | |
'asm' : ['*.asm'], | |
'actionscript' : ['*.as'], | |
'actionscript3' : ['*.as3'] | |
} | |
class PastePrivacy(): | |
Public = 0 | |
Unlisted = 1 | |
Privacy = 2 | |
dict = {'public' : 0, 'unlisted' : 1, 'privacy' : 2} | |
class ArgType(): | |
Extension = 0 | |
Privacy = 1 | |
Expires = 2 | |
Path = 3 | |
Error = 999 | |
def getFormatedDictionary(input): | |
dictionary = {} | |
for key, values in input.iteritems(): | |
for id, ext in enumerate(values): | |
dictionary[ext] = key | |
return dictionary | |
def getArgumentType(string): | |
if string.upper() in Expires: return ArgType.Expires | |
if string.lower() in Extensions.values(): return ArgType.Extension | |
if string.lower() in PastePrivacy.dict: return ArgType.Privacy | |
if os.path.isfile(string): return ArgType.Path | |
return ArgType.Error | |
Extensions = getFormatedDictionary(Highlights) | |
Expires = [ 'N', '10M', '1H', '1D', '1W', '2W', '1M' ] | |
def file_get_contents(filename): | |
with open(filename) as f: | |
return f.read() | |
def IntToEnum(Class, search): | |
for key, value in Class.__dict__.iteritems(): | |
if value == search: | |
return Class.__name__ + "." + key | |
return "NULL" | |
def CmdHelp(): | |
print "patebincom <PATH> [EXPIRES] [PRIVACY] [HIGHLIGHT]" | |
print "EXPIRES: " + ", ".join(Expires) | |
print "PRIVACY: " + ", ".join(PastePrivacy.dict) | |
print "HIGHLIGHT: " + ", ".join(Extensions.values()) | |
sys.exit(0) | |
def MakePaste(path, privacy, expires, highlight): | |
api_key = '038888494b3ed5d3d1817de4cd363afc'; | |
url = 'http://pastebin.com/api/api_post.php' | |
data = { | |
'api_option' : 'paste', | |
'api_dev_key' : api_key, | |
'api_paste_private' : PastePrivacy.dict[privacy], | |
'api_paste_name' : path, | |
'api_paste_format' : highlight, | |
'api_paste_expire_date' : expires, | |
'api_user_key' : '', | |
'api_paste_code' : file_get_contents(path) | |
} | |
opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1)) | |
req = urllib2.Request(url, urllib.urlencode(data)) | |
response = urllib2.urlopen(req) | |
print response.read() | |
if __name__ == '__main__': | |
expires = "N" | |
privacy = "public" | |
highlight = "text" | |
path = "" | |
if len(sys.argv) < 2: CmdHelp() | |
for id, arg in enumerate(sys.argv): | |
if (id == 0): continue | |
type = getArgumentType(arg) | |
if type == ArgType.Privacy: privacy = arg.lower() | |
if type == ArgType.Expires: expires = arg.upper() | |
if type == ArgType.Extension: highlight = arg.lower() | |
if type == ArgType.Path: path = arg | |
if path == "": | |
print "There is no path was specefied..." | |
CmdHelp() | |
MakePaste(path, privacy, expires, highlight) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment