Last active
August 18, 2017 13:59
-
-
Save gavin19/7874646 to your computer and use it in GitHub Desktop.
Reddit migrate flair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import praw | |
username = 'someuser' | |
password = 'somepassword' | |
user_agent = '/u/someuser for /r/yoursub' | |
client_id = 'abc123' | |
client_secret = 'xyz789' | |
reddit = praw.Reddit(user_agent=user_agent, | |
client_id=client_id, | |
client_secret=client_secret, | |
username=username, | |
password=password) | |
source_sub = 'somesourcesub' | |
target_sub = 'sometargetsub' | |
# Grab flairs from source subreddit | |
flair = reddit.subreddit(source_sub).flair(limit=None) | |
# Dump flair entries into a list | |
flair_map = [] | |
for item in flair: | |
if item['flair_text'] is None: | |
item['flair_text'] = '' | |
if item['flair_css_class'] is None: | |
item['flair_css_class'] = '' | |
flair_map.append(item) | |
# Migrate flairs to target subreddit | |
reddit.subreddit(target_sub).flair.update(flair_map) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment