jakeable

whitelist.py

Dec 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. # config
  5. client_id=''
  6. client_secret=''
  7. username = ''
  8. password = ''
  9. subreddit_name = '' # replace with your subreddit name
  10. domains = [] # comma separated domains go here
  11. user_agent = 'reddit alpha whitelist uploader v1.0 by u/Jakeable running as u/' + username
  12.  
  13. # request bearer token
  14. client_auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
  15. post_data = {"grant_type": "password", "username": username, "password": password}
  16. headers = {"User-Agent": user_agent}
  17. response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, data=post_data, headers=headers)
  18. bot_auth = response.json()['access_token']
  19.  
  20. # update whitelist data
  21. bearer = "bearer " + bot_auth
  22. headers = {"Authorization": bearer, "User-Agent": user_agent, "Content-Type": 'application/json'}
  23.  
  24. url = "https://oauth.reddit.com/api/v1/" + subreddit_name + "/submit_validations"
  25.  
  26. data = {"ruleLinkListPermission":"whitelist","ruleLinkWhitelist":domains}
  27. resp = requests.patch(url, headers=headers, data=json.dumps(data))
  28. print(resp.text)
Add Comment
Please, Sign In to add comment