From 7e2af9e063e85502f42773ec3c20a58b1cda38b7 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 1 Jul 2022 19:31:28 -0400 Subject: [PATCH] refactor: moved save_data func to utils/videos.py from final_video.py refactor: refactored using black formatter. cmd: black . --line-length 101 --- utils/console.py | 2 +- video_creation/final_video.py | 25 +------------------------ video_creation/screenshot_downloader.py | 1 + 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/utils/console.py b/utils/console.py index cd72fd0..5b91fef 100644 --- a/utils/console.py +++ b/utils/console.py @@ -53,7 +53,7 @@ def handle_input( if re.match(match, user_input) is not None: if check_type is not False: 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: console.print("[red]" + oob_error) # Input too low failstate continue diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 5c6fd15..d170169 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 -import json import multiprocessing import os import re -import time from os.path import exists from moviepy.editor import ( @@ -20,6 +18,7 @@ from rich.console import Console from utils.cleanup import cleanup from utils.console import print_step, print_substep +from utils.videos import save_data console = Console() @@ -142,25 +141,3 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): print_step( 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) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index c93427a..aa1c9d9 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -4,6 +4,7 @@ from os import getenv from pathlib import Path from playwright.async_api import async_playwright # pylint: disable=unused-import + # do not remove the above line from playwright.sync_api import sync_playwright, ViewportSize