diff --git a/.env.template b/.env.template index cab265e..6b55f99 100644 --- a/.env.template +++ b/.env.template @@ -1,10 +1,15 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" + REDDIT_USERNAME="" REDDIT_PASSWORD="" + # Valid options are "yes" and "no" REDDIT_2FA="" +#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. +RANDOM_THREAD="no" + # Valid options are "light" and "dark" THEME="" diff --git a/.gitignore b/.gitignore index f88eed6..72e6fc7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ reddit-bot-351418-5560ebc49cac.json video_creation/__pycache__/ .setup-done-before __pycache__ +.idea/ +.DS_Store out diff --git a/README.md b/README.md index d28de53..b7f6012 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) [ + @@ -20,13 +21,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Disclaimers 🚨 -- This is purely for fun purposes. -- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues. +- This is purely for fun purposes. +- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues. ## Requirements -- Python 3.6+ -- Playwright (this should install automatically during installation) +- Python 3.6+ +- Playwright (this should install automatically during installation) ## Installation 👩‍💻 @@ -44,7 +45,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p If you want to see more detailed guide, please refer to the official [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). -*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! +\*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve 📈 @@ -52,8 +53,8 @@ In its current state, this bot does exactly what it needs to do. However, lots o I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute! -- [ ] Allowing users to choose a reddit thread instead of being randomized. -- [ ] Allowing users to choose a background that is picked instead of the Minecraft one. -- [x] Allowing users to choose between any subreddit. -- [ ] Allowing users to change voice. -- [ ] Creating better documentation and adding a command line interface. \ No newline at end of file +- [x] Allowing users to choose a reddit thread instead of being randomized. +- [ ] Allowing users to choose a background that is picked instead of the Minecraft one. +- [x] Allowing users to choose between any subreddit. +- [ ] Allowing users to change voice. +- [ ] Creating better documentation and adding a command line interface. diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 58ada57..24150a0 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -14,8 +14,6 @@ def get_subreddit_threads(): load_dotenv() - print_step("Getting AskReddit threads...") - if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" @@ -35,27 +33,33 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) - - if os.getenv("SUBREDDIT"): - subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) + + # If the user specifies that he doesnt want a random thread, or if he doesn't insert the "RANDOM_THREAD" variable at all, ask the thread link + if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no": + print_substep("Insert the full thread link:", style="bold green") + thread_link = input() + print_step(f"Getting the inserted thread...") + submission = reddit.submission(url=thread_link) else: - # ! Prompt the user to enter a subreddit - try: - subreddit = reddit.subreddit( - re.sub( - r"r\/", "", input("What subreddit would you like to pull from? ") + # Otherwise, picks a random thread from the inserted subreddit + if os.getenv("SUBREDDIT"): + subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) + else: + # ! Prompt the user to enter a subreddit + 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.") + except ValueError: + subreddit = reddit.subreddit("askreddit") + print_substep("Subreddit not defined. Using AskReddit.") + + threads = subreddit.hot(limit=25) + submission = list(threads)[random.randrange(0, 25)] - threads = subreddit.hot(limit=25) - submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") console.log("Getting video comments...") try: - content["thread_url"] = submission.url content["thread_title"] = submission.title content["comments"] = []