Allow SUBREDDIT to be blank

This feature was in an old version but was removed in a recent PR. It allows the env variable SUBREDDIT to be blank and the user input to be blank which will default to AskReddit instead of an error. It also automatically filters out any special characters (in case someone types r/) from the subreddit using re.
pull/549/head
Owen Gaspard 3 years ago
parent 365ebef0d3
commit 9ba6dab73c

@ -7,6 +7,8 @@ from utils.subreddit import get_subreddit_undone
from utils.videos import check_done
from praw.models import MoreComments
import re
TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890")
@ -44,12 +46,18 @@ def get_subreddit_threads():
print_step("Getting subreddit threads...")
if not getenv(
"SUBREDDIT"
): # note to self. you can have multiple subreddits via reddit.subreddit("redditdev+learnpython")
subreddit = reddit.subreddit(
input("What subreddit would you like to pull from? ")
) # if the env isnt set, ask user
): # note to self. you can have multiple subreddits via reddit.subreddit("redditdev+learnpython")
try:
subreddit = reddit.subreddit(
re.sub(r"r\/", "",input("What subreddit would you like to pull from? "))
)
except ValueError:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.")
else:
print_substep(f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config")
print_substep(
f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config"
)
subreddit = reddit.subreddit(
getenv("SUBREDDIT")
) # Allows you to specify in .env. Done for automation purposes.

Loading…
Cancel
Save