From 0c7a1feffa4d106ed0cc25fa6e2864bd04758ded Mon Sep 17 00:00:00 2001 From: Harpo Date: Fri, 29 Dec 2023 22:48:53 -0800 Subject: [PATCH] Adds data dir config --- otto/config.py | 2 +- otto/getdata.py | 11 ++++++++--- otto/preview.py | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/otto/config.py b/otto/config.py index eddca3f..6581b35 100644 --- a/otto/config.py +++ b/otto/config.py @@ -1,7 +1,7 @@ from os import environ LOG_DIR = environ.get('LOG_DIR', 'logs') - +DATA_DIR = environ.get('DATA_DIR', 'data') defaults = { 'fontcolor': '#FFFFFF', diff --git a/otto/getdata.py b/otto/getdata.py index c24d9bc..cdb5fbe 100644 --- a/otto/getdata.py +++ b/otto/getdata.py @@ -1,4 +1,3 @@ -from csv import reader from hashlib import sha256 from json import loads from os import path @@ -6,6 +5,8 @@ from requests import head +from otto.config import DATA_DIR +from otto.log import log from otto.utils import download_url content_types = ['image/jpeg', 'video/mp4', 'image/png', 'audio/mpeg'] @@ -16,7 +17,7 @@ def sha(s): return sha256(s.encode()).hexdigest() -def download(url, location='data'): +def download(url, location=DATA_DIR): if not url.startswith('http'): return url h = head(url, allow_redirects=True) @@ -45,6 +46,8 @@ def download(url, location='data'): def openCsv(path): + from csv import reader + csvreader = reader(open(path, 'r')) d = {} for row in csvreader: @@ -75,5 +78,7 @@ def urlToJson(path): source = response.read() data = loads(source) else: - print('An error occurred while attempting to retrieve data from the API.') + log.error( + 'An error occurred while attempting to retrieve data from the API.' + ) return data diff --git a/otto/preview.py b/otto/preview.py index dd4a652..008820b 100644 --- a/otto/preview.py +++ b/otto/preview.py @@ -3,6 +3,7 @@ from otto.render import generateEdl from otto.getdata import timestr from os.path import join +from otto.config import DATA_DIR previewAPI = APIRouter() @@ -22,7 +23,7 @@ async def previewFrame(t: float, render: Render): video = generateEdl( Edl(clips=active_clips), moviesize=(render.width, render.height) ) - frame_name = join('data', timestr() + '.jpg') + frame_name = join(DATA_DIR, timestr() + '.jpg') print(f'saving frame {t} as: {frame_name}', video) video.save_frame(frame_name, t=t, withmask=False) return frame_name