Skip to content

Commit

Permalink
Adds data dir config
Browse files Browse the repository at this point in the history
  • Loading branch information
mrharpo committed Dec 30, 2023
1 parent c201775 commit 0c7a1fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion otto/config.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
11 changes: 8 additions & 3 deletions otto/getdata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from csv import reader
from hashlib import sha256
from json import loads
from os import path
from time import strftime

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']
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion otto/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

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

0 comments on commit 0c7a1fe

Please sign in to comment.