Merge pull request #4 from owengaspard/master
Add feature to allow user to choose which subreddit to pull from
This commit is contained in:
4 files changed
+28
-13
No files matched your search
+3
-1
@@ -1,4 +1,6 @@
|
||||
REDDIT_CLIENT_ID=""
|
||||
REDDIT_CLIENT_SECRET=""
|
||||
REDDIT_USERNAME=""
|
||||
REDDIT_PASSWORD=""
|
||||
REDDIT_PASSWORD=""
|
||||
|
||||
SUBREDDIT=""
|
||||
@@ -33,18 +33,19 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
|
||||
1. Clone this repository
|
||||
2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files.
|
||||
3. Run `pip3 install -r requirements.txt`
|
||||
4. Run `python3 main.py`
|
||||
5. ...
|
||||
6. Enjoy 😎
|
||||
4. Run `playwright install` and `playwright install-deps`.
|
||||
5. Run `python3 main.py`
|
||||
6. ...
|
||||
7. Enjoy 😎
|
||||
|
||||
## Contributing & Ways to improve 📈
|
||||
|
||||
In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made.
|
||||
|
||||
I have tried to simplify the code so anyone can read it and start contibuting 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.
|
||||
- [ ] Allowing users to choose a background that is picked instead of the Minecraft one.
|
||||
- [ ] Allowing users to choose between any subreddit.
|
||||
- [x] Allowing users to choose between any subreddit.
|
||||
- [ ] Allowing users to change voice.
|
||||
- [ ] Creating better documentation and adding a command line interface.
|
||||
@@ -1,6 +1,6 @@
|
||||
from utils.console import print_markdown
|
||||
import time
|
||||
from reddit.askreddit import get_askreddit_threads
|
||||
from reddit.subreddit import get_subreddit_threads
|
||||
from video_creation.background import download_background, chop_background_video
|
||||
from video_creation.voices import save_text_to_mp3
|
||||
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
|
||||
@@ -13,7 +13,7 @@ print_markdown(
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
reddit_object = get_askreddit_threads()
|
||||
reddit_object = get_subreddit_threads()
|
||||
|
||||
length, number_of_comments = save_text_to_mp3(reddit_object)
|
||||
download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
|
||||
|
||||
@@ -5,12 +5,12 @@ from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
|
||||
def get_askreddit_threads():
|
||||
def get_subreddit_threads():
|
||||
"""
|
||||
Returns a list of threads from the AskReddit subreddit.
|
||||
"""
|
||||
|
||||
print_step("Getting AskReddit threads...")
|
||||
print_step("Getting subreddit threads...")
|
||||
|
||||
content = {}
|
||||
load_dotenv()
|
||||
@@ -21,8 +21,20 @@ def get_askreddit_threads():
|
||||
username=os.getenv("REDDIT_USERNAME"),
|
||||
password=os.getenv("REDDIT_PASSWORD"),
|
||||
)
|
||||
askreddit = reddit.subreddit("askreddit")
|
||||
threads = askreddit.hot(limit=25)
|
||||
|
||||
if os.getenv("SUBREDDIT"):
|
||||
subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
|
||||
else:
|
||||
# ! Prompt the user to enter a subreddit
|
||||
try:
|
||||
subreddit = reddit.subreddit(
|
||||
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)]
|
||||
print_substep(f"Video will be: {submission.title} :thumbsup:")
|
||||
try:
|
||||
@@ -42,5 +54,5 @@ def get_askreddit_threads():
|
||||
|
||||
except AttributeError as e:
|
||||
pass
|
||||
print_substep("Received AskReddit threads Successfully.", style="bold green")
|
||||
print_substep("Received subreddit threads Successfully.", style="bold green")
|
||||
return content
|
||||
Reference in new issue
Block a user