pastebin- python wrapper for the pastebin api |
git clone git://git.acid.vegas/pastebin.git |
Log | Files | Refs | Archive | README | LICENSE |
pastebin.py (2577B)
1 #!/usr/bin/env python 2 # PasteBin API Class - Developed by acidvegas in Python (https://git.acid.vegas/pastebin) 3 4 ''' 5 API Documentation: https://pastebin.com/doc_api 6 ''' 7 8 import urllib.parse 9 import urllib.request 10 11 class PasteBin: 12 def __init__(self, api_dev_key, api_user_key=None): 13 self.api_dev_key = api_dev_key 14 self.api_user_key = api_user_key 15 16 def api_call(self, method, params): 17 '''Make a call to the PasteBin API.''' 18 response = urllib.request.urlopen('https://pastebin.com/api/' + method, urllib.parse.urlencode(params).encode('utf-8'), timeout=10) 19 return response.read().decode() 20 21 def create_user_key(self, username, password): 22 '''Create a user key for the PasteBin API.''' 23 params = {'api_dev_key':self.api_dev_key, 'api_user_name':username, 'api_user_password':password} 24 return self.api_call('api_login.php', params) 25 26 def paste(self, data, guest=False, name=None, format=None, private=None, expire=None): 27 '''Create a paste on PasteBin.''' 28 params = {'api_dev_key':self.api_dev_key, 'api_option':'paste', 'api_paste_code':data} 29 if not guest : params['api_user_key'] = self.api_user_key 30 if name : params['api_paste_name'] = name 31 if format : params['api_paste_format'] = format 32 if private : params['api_paste_private'] = private 33 if expire : params['api_paste_expire_date'] = expire 34 return self.api_call('api_post.php', params) 35 36 def list_pastes(self, results_limit=None): 37 '''List pastes created by the user.''' 38 params = {'api_dev_key':self.api_dev_key, 'api_user_key':self.api_user_key, 'api_option':'list'} 39 if results_limit: 40 params['api_results_limit'] = results_limit 41 return self.api_call('api_post.php', params) 42 43 def trending_pastes(self): 44 '''List trending pastes.''' 45 params = {'api_dev_key':self.api_dev_key, 'api_option':'trends'} 46 return self.api_call('api_post.php', params) 47 48 def delete_paste(self, paste_key): 49 '''Delete a paste.''' 50 params = {'api_dev_key':self.api_dev_key, 'api_user_key':self.api_user_key, 'api_paste_key':paste_key, 'api_option':'delete'} 51 return self.api_call('api_post.php', params) 52 53 def user_info(self): 54 '''Get information about the user.''' 55 params = {'api_dev_key':self.api_dev_key, 'api_user_key':self.api_user_key, 'api_option':'userdetails'} 56 return self.api_call('api_post.php', params) 57 58 def raw_pastes(self, paste_key): 59 '''Get the raw data of a paste.''' 60 params = {'api_dev_key':self.api_dev_key, 'api_user_key':self.api_user_key, 'api_paste_key':paste_key, 'api_option':'show_paste'} 61 return self.api_call('api_raw.php', params)