refactor: moved save_data func to utils/videos.py from final_video.py

refactor: refactored using black formatter.

cmd: black . --line-length 101
pull/790/head^2
Jason 2 years ago
parent 03feb2e8ea
commit 7e2af9e063

@ -53,7 +53,7 @@ def handle_input(
if re.match(match, user_input) is not None: if re.match(match, user_input) is not None:
if check_type is not False: if check_type is not False:
try: try:
user_input = check_type(user_input) # this line is fine user_input = check_type(user_input) # this line is fine
if nmin is not None and user_input < nmin: if nmin is not None and user_input < nmin:
console.print("[red]" + oob_error) # Input too low failstate console.print("[red]" + oob_error) # Input too low failstate
continue continue

@ -1,9 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import json
import multiprocessing import multiprocessing
import os import os
import re import re
import time
from os.path import exists from os.path import exists
from moviepy.editor import ( from moviepy.editor import (
@ -20,6 +18,7 @@ from rich.console import Console
from utils.cleanup import cleanup from utils.cleanup import cleanup
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.videos import save_data
console = Console() console = Console()
@ -142,25 +141,3 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]):
print_step( print_step(
f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {os.getenv("background_credit")}' f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {os.getenv("background_credit")}'
) )
def save_data(filename: str, reddit_title: str, reddit_id: str):
"""Saves the videos that have already been generated to a JSON file in video_creation/data/videos.json
Args:
filename (str): The finished video title name
"""
with open("./video_creation/data/videos.json", "r+", encoding="utf-8") as raw_vids:
done_vids = json.load(raw_vids)
if reddit_id in [video["id"] for video in done_vids]:
return # video already done but was specified to continue anyway in the .env file
payload = {
"id": reddit_id,
"time": str(int(time.time())),
"background_credit": str(os.getenv("background_credit")),
"reddit_title": reddit_title,
"filename": filename,
}
done_vids.append(payload)
raw_vids.seek(0)
json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4)

@ -4,6 +4,7 @@ from os import getenv
from pathlib import Path from pathlib import Path
from playwright.async_api import async_playwright # pylint: disable=unused-import from playwright.async_api import async_playwright # pylint: disable=unused-import
# do not remove the above line # do not remove the above line
from playwright.sync_api import sync_playwright, ViewportSize from playwright.sync_api import sync_playwright, ViewportSize

Loading…
Cancel
Save