Merge pull request #238 from DomizianoScarcelli/master

Allowing users to choose a reddit thread instead of being randomized
pull/323/head
Lewis Menelaws 3 years ago committed by GitHub
commit be397a0226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,10 +1,15 @@
REDDIT_CLIENT_ID="" REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
# Valid options are "yes" and "no" # Valid options are "yes" and "no"
REDDIT_2FA="" 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" # Valid options are "light" and "dark"
THEME="" THEME=""

2
.gitignore vendored

@ -2,4 +2,6 @@ assets/
.env .env
reddit-bot-351418-5560ebc49cac.json reddit-bot-351418-5560ebc49cac.json
__pycache__ __pycache__
.idea/
.DS_Store
out out

@ -7,6 +7,7 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi
Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca)
[<picture> [<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/6053155/170528535-e274dc0b-7972-4b27-af22-637f8c370133.png"> <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/6053155/170528535-e274dc0b-7972-4b27-af22-637f8c370133.png">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png"> <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png">
<img src="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png" width="350"> <img src="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png" width="350">
@ -20,13 +21,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
## Disclaimers 🚨 ## Disclaimers 🚨
- This is purely for fun purposes. - 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. - **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 ## Requirements
- Python 3.6+ - Python 3.6+
- Playwright (this should install automatically during installation) - Playwright (this should install automatically during installation)
## Installation 👩‍💻 ## Installation 👩‍💻
@ -38,7 +39,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
6. Enjoy 😎 6. Enjoy 😎
If you want to see more detailed guide, please refer to the official [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). 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 📈 ## Contributing & Ways to improve 📈
@ -46,8 +47,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! 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. - [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. - [ ] Allowing users to choose a background that is picked instead of the Minecraft one.
- [x] Allowing users to choose between any subreddit. - [x] Allowing users to choose between any subreddit.
- [ ] Allowing users to change voice. - [ ] Allowing users to change voice.
- [ ] Creating better documentation and adding a command line interface. - [ ] Creating better documentation and adding a command line interface.

@ -2,6 +2,7 @@ from utils.console import print_markdown, print_step, print_substep
from dotenv import load_dotenv from dotenv import load_dotenv
import os, random, praw, re import os, random, praw, re
def get_subreddit_threads(): def get_subreddit_threads():
global submission global submission
""" """
@ -10,8 +11,6 @@ def get_subreddit_threads():
load_dotenv() load_dotenv()
print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
print( print(
"\nEnter your two-factor authentication code from your authenticator app.\n" "\nEnter your two-factor authentication code from your authenticator app.\n"
@ -32,37 +31,48 @@ def get_subreddit_threads():
username=os.getenv("REDDIT_USERNAME"), username=os.getenv("REDDIT_USERNAME"),
password=passkey, password=passkey,
) )
# 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 os.getenv("SUBREDDIT"): if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no":
subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) 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: else:
# ! Prompt the user to enter a subreddit # Otherwise, picks a random thread from the inserted subreddit
try: if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit( subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) else:
) # ! Prompt the user to enter a subreddit
except ValueError: try:
subreddit = reddit.subreddit("askreddit") subreddit = reddit.subreddit(
print_substep("Subreddit not defined. Using AskReddit.") 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.")
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:") print_substep(f"Video will be: {submission.title} :thumbsup:")
try: try:
content["thread_url"] = submission.url content["thread_url"] = submission.url
content["thread_title"] = submission.title content["thread_title"] = submission.title
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
if not top_level_comment.stickied: if not top_level_comment.stickied:
content["comments"].append( content["comments"].append(
{ {
"comment_body": top_level_comment.body, "comment_body": top_level_comment.body,
"comment_url": top_level_comment.permalink, "comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id, "comment_id": top_level_comment.id,
} }
) )
except AttributeError as e: except AttributeError as e:
pass pass

Loading…
Cancel
Save