Hack Forums
[Python] Pastebin Client, download, paste (from file or data) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Pastebin Client, download, paste (from file or data) (/showthread.php?tid=3529700)



Pastebin Client, download, paste (from file or data) - Hannah Montana - Jun 5, 2013

PHP Code

<?php 
import urllib
import sys
import md5
import urlparse
import urllib2

key 
= "d974f286bc3bf50c7de439ca395b7a8f"
url = "http://pastebin.com/api/api_post.php"

def usage():
    print(
'Usage:    ')
    print(
'  %s download pastebin.com/NXaHrrEs pastebin.com/7PfbBGR4' % sys.argv[0])
    print(
'  %s paste file C:\\boot.ini' % sys.argv[0])
    print(
'  %s paste Data you want to send.' % sys.argv[0])
    print(
'\n Made by Hannah Montana/obnoxious')
    
sys.exit()

if 
len(sys.argv) == 1 or len(sys.argv) == 2:
    
usage()

if 
'help' in sys.argv[1]:
    
usage()

if 
'download' in sys.argv[1]:
    for 
i in range(len(sys.argv)):
        if 
sys.argv[i].count('/') >= 3 and i != 0 and i != 1:
            
url = sys.argv[i].split('/')[3]
            
urllib.urlretrieve('http://pastebin.com/raw.php?i=%s' % url, url)
            print(
'%s has finished downloading.' % url)
        
elif sys.argv[i].count('/') >= 1 and i !=0 and i != 1:
            
url = sys.argv[i].split('/')[1]
            
urllib.urlretrieve('http://pastebin.com/raw.php?i=%s' % url, url)
            print(
'%s has finished downloading.' % url)

if 
'paste' in sys.argv[1]:
    if 
'file' in sys.argv[2]:
        
fileData = open(sys.argv[3], 'r').read()
        
data = {}
        
data["api_dev_key"] = key
        data
["api_option"] = "paste"
        
data["api_paste_name"] = md5.md5(fileData).hexdigest()
        
data["api_paste_code"] = fileData
        data
["api_paste_private"] = sys.argv[4]
        
urlEncode = urllib.urlencode(data).encode("utf8")
        
resultUrl = urllib2.urlopen(url, urlEncode).read().decode("utf-8")

        print 
resultUrl

    
else:
        
pasteData = sys.argv[2:]
        
data = {}
        
data["api_dev_key"] = key
        data
["api_option"] = "paste"
        
data["api_paste_name"] = md5.md5(''.join(pasteData)).hexdigest()
        
data["api_paste_code"] = ' '.join(pasteData)
        
data["api_paste_private"] = 1
        urlEncode 
= urllib.urlencode(data).encode("utf8")
        
resultUrl = urllib2.urlopen(url, urlEncode).read().decode("utf-8")

        print 
resultUrl 

I barrowed some code from jhpy (the guy who made pyPaste, The API key isn't mine it's his. His fault for putting it on github lel.)

How to use
pastebinClient.py help


* - __init__ - Jun 5, 2013

Haha, thanks for stealing my API key :D

Good little tool anyway :)


* - glob - Jun 5, 2013

I wouldn't say it's bad, but it also isn't good.

Don't steal code/API keys :/


* - __init__ - Jun 5, 2013

(Jun 5, 2013 02:21 PM)Cᴀᴛᴀʟʏsᴛ Wrote:  I wouldn't say it's bad, but it also isn't good.

Don't steal code/API keys :/

He didn't really steal it, we were talking on irc and basically let him use it.


* - glob - Jun 5, 2013

It doesn't matter if you let him or not, he is releasing your code :p


* - antigrav - Jun 5, 2013

(Jun 5, 2013 02:36 PM)Cᴀᴛᴀʟʏsᴛ Wrote:  It doesn't matter if you let him or not, he is releasing your code :p

Haha, technically he released his own code. Even if he went back and changed it in the GitHub repo, I'm pretty sure people can view the entire history of every change in the code, which would include the one in which he removed it.


* - Hannah Montana - Jun 5, 2013

(Jun 5, 2013 02:36 PM)Cᴀᴛᴀʟʏsᴛ Wrote:  It doesn't matter if you let him or not, he is releasing your code :p

The only code I used from him was the pastebin API usage and there is nothing wrong with releasing the code with permission.

EDIT: I could have made it quite a bit better too now looking at it but meh.


* - glob - Jun 5, 2013

(Jun 5, 2013 05:11 PM)Hannah Montana Wrote:  The only code I used from him was the pastebin API usage and there is nothing wrong with releasing the code with permission.

EDIT: I could have made it quite a bit better too now looking at it but meh.

You don't learn anything if you release other people's code whether you have permission or not.


* - Hannah Montana - Jun 5, 2013

(Jun 5, 2013 06:18 PM)Cᴀᴛᴀʟʏsᴛ Wrote:  You don't learn anything if you release other people's code whether you have permission or not.

I don't learn anything? I learned from reading it.


* - MadHunteR - Jun 12, 2013

Good work. Thank you for share brother.


* - feudin - Jun 12, 2013

Code
def usage():
    print('''Usage:    
{0} download pastebin.com/NXaHrrEs pastebin.com/7PfbBGR4
{0} paste file C:\\boot.ini
{0} paste Data you want to send
{0} Made by Hannah Montana/obnoxious'''.format(sys.argv[0]))
    exit()

Look into using argparse module.

It will allow you to type "$python scriptname.py -h" and it will automatically give the user information on the command line arguments