2023-04-20 13:10:08 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from datetime import date, timedelta
|
|
|
|
import json
|
2023-04-20 14:51:19 +00:00
|
|
|
import os.path
|
|
|
|
import requests
|
2023-04-20 13:10:08 +00:00
|
|
|
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
|
|
|
|
|
|
|
BASE_DATE = date(2023, 4, 17)
|
|
|
|
|
|
|
|
def to_date(offset: int, date_format="%d/%m/%Y"):
|
|
|
|
return (BASE_DATE + timedelta(days=offset)).strftime(date_format)
|
|
|
|
|
|
|
|
|
|
|
|
def generate():
|
2023-04-20 14:51:19 +00:00
|
|
|
if not os.path.exists('output'):
|
|
|
|
os.mkdir('output')
|
|
|
|
|
|
|
|
if not os.path.exists('output/subtitles'):
|
|
|
|
os.mkdir('output/subtitles')
|
|
|
|
|
2023-04-20 13:10:08 +00:00
|
|
|
with open('data.json') as f:
|
|
|
|
data = json.load(f)
|
|
|
|
|
2023-04-20 14:51:19 +00:00
|
|
|
for day in data:
|
|
|
|
for event in day['events']:
|
|
|
|
for medium in event['media']:
|
|
|
|
if 'subtitles_link' in medium:
|
|
|
|
req = requests.get(medium['subtitles_link'], stream=True)
|
|
|
|
|
|
|
|
with open(os.path.join('output/subtitles', medium['subtitles_file']), 'wb') as f:
|
|
|
|
for chunk in req.iter_content(chunk_size=1024):
|
|
|
|
if chunk:
|
|
|
|
f.write(chunk)
|
|
|
|
|
2023-04-20 13:10:08 +00:00
|
|
|
env = Environment(loader=FileSystemLoader("templates/"))
|
|
|
|
env.filters['to_date'] = to_date
|
|
|
|
template = env.get_template("template.html.j2")
|
|
|
|
|
|
|
|
with open('output/index.html', 'w') as f:
|
|
|
|
f.write(template.render(data=data))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
generate()
|