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 3 years ago
parent 03feb2e8ea
commit 7e2af9e063

@ -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

@ -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)

@ -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

Loading…
Cancel
Save