Created
November 28, 2016 04:38
-
-
Save hasherezade/a3d994151754efb0a94a79b60a08da9b to your computer and use it in GitHub Desktop.
Pastebin API test
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/python2.7 | |
| import sys | |
| import urllib2 | |
| method = 'POST' | |
| content_type = 'text/html' | |
| agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20130921 Firefox/24.0' | |
| host = 'pastebin.com' | |
| site = '/api/api_post.php' | |
| dev_key = ''#paste your dev key here | |
| login = ''#paste your login here | |
| password = ''#paste your password here | |
| def data_fetch(site, data): | |
| url = 'http://' + host +'/'+ site | |
| request = urllib2.Request(url, data, {'Host': host, 'User-Agent' : agent}) | |
| request.get_method = lambda: method | |
| resp = urllib2.urlopen(request) | |
| rcode = resp.getcode() | |
| resp_content = resp.read() | |
| if rcode != 200: | |
| return None | |
| print "200 OK" | |
| return resp_content | |
| def pastebin_login(login, password): | |
| login_site = 'api/api_login.php' | |
| login_data = 'api_dev_key='+dev_key+'&api_user_name='+login+'&api_user_password='+password | |
| return data_fetch(login_site, login_data) | |
| def paste_data(dev_key, user_key, data): | |
| post_data = 'api_dev_key='+dev_key+'&api_option=paste&api_paste_code='+data+'&api_paste_private=0&api_paste_name=test1.txt&api_paste_expire_date=1M&api_paste_format=text&api_user_key='+user_key | |
| return data_fetch(site, post_data) | |
| def fetch_data(dev_key, user_key): | |
| retrieve_data ='api_dev_key='+dev_key+'&api_option=list&api_user_key='+user_key | |
| return data_fetch(site, retrieve_data) | |
| def main(): | |
| user_key = pastebin_login(login, password) | |
| data = "Test 1234" | |
| resp = paste_data(dev_key, user_key, data) | |
| print resp | |
| resp = fetch_data(dev_key, user_key) | |
| print resp | |
| return(0) | |
| if __name__ == "__main__": | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment