Guest User

Untitled

a guest
May 31st, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import praw
  2. import pprint
  3. import json
  4.  
  5. filename = 'user.subs'
  6. user_agent = 'test-py'
  7. client_id='xxx'
  8. client_secret="xxx"
  9. username='xxx'
  10. password='xxx'
  11.  
  12. reddit = praw.Reddit(user_agent=user_agent,
  13. client_id=client_id, client_secret=client_secret,
  14. username=username, password=password)
  15.  
  16. try:
  17. x = reddit.user.me()
  18. my_subs = set()
  19. for sub in reddit.user.subreddits(limit=None):
  20. my_subs.add(str(sub))
  21. pprint.pprint(my_subs)
  22.  
  23. fh = open(filename, 'w')
  24. subs = sorted(my_subs, key=str.lower)
  25. json.dump(subs, fh, indent=2)
  26. fh.close()
  27. except Exception as exc:
  28. pprint.pprint(vars(exc))
Add Comment
Please, Sign In to add comment