reddit thread picking works!

pull/418/head
Jason 3 years ago
parent 81e8a5d6fb
commit 19cbe21a6d

@ -4,3 +4,4 @@ REDDIT_USERNAME=""
REDDIT_PASSWORD=""
SUBREDDIT="AskReddit"
ALLOW_NSFW="False"
POST_ID=""

@ -36,14 +36,15 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
4. install [SoX](https://sourceforge.net/projects/sox/files/sox/)
5. Run `python3 main.py`
6. Enjoy 😎
## Usage
* an example of a reddit ID is ult7el
## 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!
- [ ] Allowing users to choose a reddit thread instead of being randomized.
- [x] Allowing users to choose a reddit thread instead of being randomized.
- [x] 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 change voice.

@ -4,7 +4,7 @@ from utils.console import print_step, print_substep
import praw
import random
from dotenv import load_dotenv
import os
from os import getenv, environ
def ascifi(text):
@ -26,25 +26,31 @@ def get_subreddit_threads():
content = {}
load_dotenv()
reddit = praw.Reddit(client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing AskReddit threads", username=os.getenv("REDDIT_USERNAME"),
password=os.getenv("REDDIT_PASSWORD"), )
reddit = praw.Reddit(client_id=getenv("REDDIT_CLIENT_ID"), client_secret=getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing AskReddit threads", username=getenv("REDDIT_USERNAME"),
password=getenv("REDDIT_PASSWORD"), )
"""
Ask user for subreddit input
"""
if not os.getenv("SUBREDDIT"):
if not getenv("SUBREDDIT"):
subreddit = reddit.subreddit(
input("What subreddit would you like to pull from? ")) # if the env isnt set, ask user
else:
print_substep(f"Using subreddit: r/{os.getenv('SUBREDDIT')} from environment variable config")
print_substep(f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config")
subreddit = reddit.subreddit(
os.getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes.
getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes.
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)')
if getenv('POST_ID'):
submission = reddit.submission(id=getenv('POST_ID'))
else:
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print(submission)
print_substep(
f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)')
os.environ["VIDEO_TITLE"] = str(ascifi(submission.title))
environ["VIDEO_TITLE"] = str(ascifi(submission.title))
try:
content["thread_url"] = submission.url

@ -32,7 +32,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
if getenv("ALLOW_NSFW").casefold() == "false":
print_substep("NSFW Post Detected. Skipping...")
from subprocess import call
call(["python3", "main.py"])
call(["python", "main.py"])
exit(1)
print_substep("Post is NSFW. You are spicy... :fire:")

@ -36,7 +36,7 @@ def save_text_to_mp3(reddit_obj):
ttttsw.tts(comment["comment_body"], filename=f"assets/temp/mp3/{idx}.mp3", random_speaker=False)
try:
length += MP3(f"assets/temp/mp3/{idx}.mp3").info.length
except HeaderNotFoundError or MutagenError:
except (HeaderNotFoundError, MutagenError, Exception):
length = sox.file_info.duration(f"assets/temp/mp3/{idx}.mp3")
print_substep("Saved Text to MP3 files Successfully.", style="bold green")

Loading…
Cancel
Save