From f9c752190a12c975bada890b097216ca07129537 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 1 Jul 2022 20:23:37 -0400 Subject: [PATCH] FIX: lmao --- utils/videos.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/utils/videos.py b/utils/videos.py index ecbca7e..f675ecf 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -1,4 +1,6 @@ import json +import os +import time from os import getenv from praw.models import Submission @@ -31,3 +33,28 @@ def check_done( print_step("Getting new post as the current one has already been done") return None return redditobj + + +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 + @param filename: + @param reddit_id: + @param reddit_title: + """ + 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)