Advertisement
Guest User

Untitled

a guest
May 1st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import praw
  2. import praw.models
  3. from migration_config import *
  4.  
  5. def get_reddit_for_user(user):
  6. """ CLIENT_ID: registered app client id
  7. CLIENT_SECRET: registered app secret id
  8. user is a dictionary
  9.  
  10. All of the above must be specified in migration_config.py
  11. """
  12. return praw.Reddit(client_id = CLIENT_ID,
  13. client_secret = CLIENT_SECRET,
  14. password = user['pass'],
  15. user_agent = user['username'],
  16. username = user['username'])
  17.  
  18. def subscribe_target_to_src_subs(src_r, target_r):
  19. src_subs = src_r.user.subreddits(limit=None)
  20.  
  21. src_sub = src_subs.next() # Get first
  22.  
  23. if src_subs is not None:
  24. sub = target_r.subreddit(src_sub.display_name) # Get the subreddit now vinculated with the target instance
  25. sub.subscribe(other_subreddits=src_subs) # subscribe to all subreddits of the source instance
  26.  
  27. def copy_saved_links_from_src(src_r, target_r):
  28. saved_links = list(src_r.user.me().saved(limit=None))
  29. saved_links.reverse() # Start from last to most recent save
  30.  
  31. for saved in saved_links:
  32. if isinstance(saved, praw.models.Submission):
  33. target_r.submission(saved.id).save()
  34. elif isinstance(saved, praw.models.Comment):
  35. target_r.comment(saved.id).save()
  36.  
  37. def main():
  38. src_r = get_reddit_for_user(SOURCE_ACC)
  39. target_r = get_reddit_for_user(TARGET_ACC)
  40.  
  41. subscribe_target_to_src_subs(src_r, target_r)
  42. copy_saved_links_from_src(src_r, target_r)
  43.  
  44. print 'Done!'
  45.  
  46. if __name__ == 'main':
  47. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement