Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import praw.models
- from migration_config import *
- def get_reddit_for_user(user):
- """ CLIENT_ID: registered app client id
- CLIENT_SECRET: registered app secret id
- user is a dictionary
- All of the above must be specified in migration_config.py
- """
- return praw.Reddit(client_id = CLIENT_ID,
- client_secret = CLIENT_SECRET,
- password = user['pass'],
- user_agent = user['username'],
- username = user['username'])
- def subscribe_target_to_src_subs(src_r, target_r):
- src_subs = src_r.user.subreddits(limit=None)
- src_sub = src_subs.next() # Get first
- if src_subs is not None:
- sub = target_r.subreddit(src_sub.display_name) # Get the subreddit now vinculated with the target instance
- sub.subscribe(other_subreddits=src_subs) # subscribe to all subreddits of the source instance
- def copy_saved_links_from_src(src_r, target_r):
- saved_links = list(src_r.user.me().saved(limit=None))
- saved_links.reverse() # Start from last to most recent save
- for saved in saved_links:
- if isinstance(saved, praw.models.Submission):
- target_r.submission(saved.id).save()
- elif isinstance(saved, praw.models.Comment):
- target_r.comment(saved.id).save()
- def main():
- src_r = get_reddit_for_user(SOURCE_ACC)
- target_r = get_reddit_for_user(TARGET_ACC)
- subscribe_target_to_src_subs(src_r, target_r)
- copy_saved_links_from_src(src_r, target_r)
- print 'Done!'
- if __name__ == 'main':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement