pull/796/head
Jason 2 years ago
parent 51f47dc782
commit f9c752190a

@ -1,4 +1,6 @@
import json import json
import os
import time
from os import getenv from os import getenv
from praw.models import Submission 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") print_step("Getting new post as the current one has already been done")
return None return None
return redditobj 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)

Loading…
Cancel
Save