forked from lfender6445/reddit-batch-subscribe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
39 lines (29 loc) · 1.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from time import sleep
from dotenv import load_dotenv
import praw
from prawcore.exceptions import Forbidden, NotFound
# Load environment variables
load_dotenv()
# Authenticate to reddit
reddit = praw.Reddit(
user_agent='Python:batch-subscribe-v1:v1',
client_id=os.getenv('REDDIT_CLIENT_ID'),
client_secret=os.getenv('REDDIT_CLIENT_SECRET'),
username=os.getenv('REDDIT_USERNAME'),
password=os.getenv('REDDIT_PASSWORD')
)
print('Logged in as %s\n' % reddit.user.me())
# Read file contents and subscribe to everything inside
with open('list.txt', 'r') as f:
list = f.readlines()
for subreddit in list:
try:
print(f'Subscribing to {subreddit}')
reddit.subreddit(subreddit).subscribe()
# Exceptions, you can add more if you wish
except Forbidden:
print(f'Subreddit {subreddit} is private/quarantined/banned')
except NotFound:
print(f'Subreddit {subreddit} does not exist')
print('Congratulations, you have subscribed to every subreddit!')