avoid already finished threads from as requested from #225

pull/280/head
iaacornus 3 years ago
parent c85d1c77cb
commit 1f4c1835ac
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -3,6 +3,7 @@ import shutil
from dotenv import load_dotenv
import reddit.subreddit
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
@ -62,6 +63,10 @@ def main(subreddit_=None, background=None, filename=None, thread_link_=None):
download_background(background)
chop_background_video(length)
make_final_video(number_of_comments, filename)
with open("created_videos", "a", encoding="utf-8") as video_lists:
video_lists.write(reddit.subreddit.submission.title)
return True
print_substep(

@ -65,27 +65,40 @@ def get_subreddit_threads(subreddit_, thread_link_):
# 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 thread_link_ is not None:
thread_link = thread_link_
print_step("Getting the inserted thread...")
submission = reddit.submission(url=thread_link)
else:
try:
if subreddit_ is None:
raise ValueError
subreddit = reddit.subreddit(subreddit_)
except ValueError:
if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(
re.sub(r"r\/", "", os.getenv("SUBREDDIT").strip())
)
else:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.")
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
while True:
with open("created_videos", "r", encoding="utf-8") as reference:
videos = list(reference.readlines())
if thread_link_ is not None:
thread_link = thread_link_
print_step("Getting the inserted thread...")
submission = reddit.submission(url=thread_link)
else:
try:
if subreddit_ is None:
raise ValueError
subreddit = reddit.subreddit(subreddit_)
except ValueError:
if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(
re.sub(r"r\/", "", os.getenv("SUBREDDIT").strip())
)
else:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.")
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
if submission.title in videos:
print_substep(
"[bold]There is already a video for thread: [cyan]"
+ f"{submission.title}[/cyan]. Finding another one.[/bold]"
)
continue
break
print_substep(f"Video will be: [cyan]{submission.title}[/cyan] :thumbsup:")

Loading…
Cancel
Save