AyanUpadhaya

Pastebin Automation

May 14th, 2021 (edited)
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. #post to pastebin automation
  2. #the program will launch and will ask the user to enter the file path and enter paste name
  3. #the program will post the source code of the file in pastebin
  4. #you will need an api_dev_key and api_user_key to perform this automation
  5. #get the api_dev_key from https://pastebin.com/doc_api
  6. #create a creds.py file and store your keys as api_dev_key and api_user_key
  7. #import creds in the main file
  8. #run the program from terminal
  9. #script writtern by Ayan Upadhaya, contact: ayanU881@gmail.com
  10.  
  11. import requests
  12. from creds import*
  13.  
  14. class Pastebin:
  15.     def __init__(self):
  16.         self.API_ENDPOINT="https://pastebin.com/api/api_post.php"
  17.         self.api_dev_key  = api_dev_key
  18.         self.api_user_key = api_user_key
  19.    
  20.     def post_pastebin(self,file_path,paste_name):
  21.  
  22.         with open(file_path,'r') as f:
  23.             source_data=f.read()
  24.         data={
  25.         'api_dev_key':self.api_dev_key,
  26.         'api_user_key':self.api_user_key,
  27.         'api_option':'paste',
  28.         'api_paste_code':source_data,
  29.         'api_paste_name':paste_name,}
  30.  
  31.         r=requests.post(url=self.API_ENDPOINT,data=data)
  32.  
  33.         print(r)
  34.         print(r.text)
  35.  
  36.  
  37. """
  38. generate user key for posting as pastebin member
  39. ================================================
  40. from https://pastebin.com/doc_api get the api_dev_key
  41. to generate the user key create a separate py file, copy the below codes.
  42. Then pass your api_dev_key, your username and password of pastebin as arguments(line: 57) in generate_user_key funtion()
  43. This will return an user key. copy that and save it in your creds.py file as api_user_key variable
  44. """
  45. """
  46. def generate_user_key(api_dev_key,api_user_name,api_user_password):
  47.    API_ENDPOINT="https://pastebin.com/api/api_login.php"
  48.  
  49.    data={
  50.    'api_dev_key':api_dev_key,
  51.    'api_user_name':api_user_name,
  52.    'api_user_password':api_user_password
  53.    }
  54.    r=requests.post(url=API_ENDPOINT,data=data)
  55.    return r.text
  56.  
  57. print(generate_user_key(api_dev_key,api_user_name,api_user_password))
  58. """
  59.  
  60.  
  61. def main():
  62.     file_path=input("Enter the file path:")
  63.     paste_name=input("Enter paste name:")
  64.     try:
  65.         paste=Pastebin()
  66.         paste.post_pastebin(file_path,paste_name)
  67.     except Exception as e:
  68.         print(e)
  69.  
  70.  
  71. if __name__=="__main__":
  72.     main()
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
Add Comment
Please, Sign In to add comment