Created
January 14, 2020 00:11
-
-
Save fabio195/1a4b8c07455cbcd678ed4f5bf917346a to your computer and use it in GitHub Desktop.
Script to import subreddits from a JSON file
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
# imports | |
import getpass | |
import praw | |
import codecs | |
import json | |
# variables | |
user = input("Ingresar nombre de usuario: ") | |
password = getpass.getpass("Ingrese la contraseña para " + user + ": ") | |
client_id = getpass.getpass("Ingrese el client_id: ") | |
client_secret = getpass.getpass("Ingrese el client_secret: ") | |
user_agent = "Reddit Import Subs Script 1.0 by /u/fabiomun" | |
# code | |
reddit = praw.Reddit( | |
client_id = client_id, | |
client_secret = client_secret, | |
user_agent = user_agent, | |
username = user, | |
password = password | |
) | |
data = json.load(codecs.open('data.txt', 'r', 'utf-8-sig')) | |
for sub in data['Subreddits']: | |
subreddit = reddit.subreddit(sub['Nombre']) | |
praw.models.Subreddit.subscribe(subreddit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment