Skip to content

Instantly share code, notes, and snippets.

@fabio195
Created January 14, 2020 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabio195/1a4b8c07455cbcd678ed4f5bf917346a to your computer and use it in GitHub Desktop.
Save fabio195/1a4b8c07455cbcd678ed4f5bf917346a to your computer and use it in GitHub Desktop.
Script to import subreddits from a JSON file
# 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