reddit thread picking works!

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

@ -4,3 +4,4 @@ REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
SUBREDDIT="AskReddit" SUBREDDIT="AskReddit"
ALLOW_NSFW="False" 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/) 4. install [SoX](https://sourceforge.net/projects/sox/files/sox/)
5. Run `python3 main.py` 5. Run `python3 main.py`
6. Enjoy 😎 6. Enjoy 😎
## Usage
* an example of a reddit ID is ult7el
## Contributing & Ways to improve 📈 ## Contributing & Ways to improve 📈
In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. 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 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 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.
- [x] Allowing users to change voice. - [x] Allowing users to change voice.

@ -4,7 +4,7 @@ from utils.console import print_step, print_substep
import praw import praw
import random import random
from dotenv import load_dotenv from dotenv import load_dotenv
import os from os import getenv, environ
def ascifi(text): def ascifi(text):
@ -26,25 +26,31 @@ def get_subreddit_threads():
content = {} content = {}
load_dotenv() load_dotenv()
reddit = praw.Reddit(client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), reddit = praw.Reddit(client_id=getenv("REDDIT_CLIENT_ID"), client_secret=getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing AskReddit threads", username=os.getenv("REDDIT_USERNAME"), user_agent="Accessing AskReddit threads", username=getenv("REDDIT_USERNAME"),
password=os.getenv("REDDIT_PASSWORD"), ) password=getenv("REDDIT_PASSWORD"), )
""" """
Ask user for subreddit input Ask user for subreddit input
""" """
if not os.getenv("SUBREDDIT"): if not getenv("SUBREDDIT"):
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
input("What subreddit would you like to pull from? ")) # if the env isnt set, ask user input("What subreddit would you like to pull from? ")) # if the env isnt set, ask user
else: 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( 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) if getenv('POST_ID'):
submission = list(threads)[random.randrange(0, 25)] submission = reddit.submission(id=getenv('POST_ID'))
print_substep(f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)') 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: try:
content["thread_url"] = submission.url 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": if getenv("ALLOW_NSFW").casefold() == "false":
print_substep("NSFW Post Detected. Skipping...") print_substep("NSFW Post Detected. Skipping...")
from subprocess import call from subprocess import call
call(["python3", "main.py"]) call(["python", "main.py"])
exit(1) exit(1)
print_substep("Post is NSFW. You are spicy... :fire:") 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) ttttsw.tts(comment["comment_body"], filename=f"assets/temp/mp3/{idx}.mp3", random_speaker=False)
try: try:
length += MP3(f"assets/temp/mp3/{idx}.mp3").info.length 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") length = sox.file_info.duration(f"assets/temp/mp3/{idx}.mp3")
print_substep("Saved Text to MP3 files Successfully.", style="bold green") print_substep("Saved Text to MP3 files Successfully.", style="bold green")

Loading…
Cancel
Save