mirror of
https://github.com/MathiasDPX/grainParisArt.git
synced 2025-01-06 15:46:38 +00:00
multiples fixes
This commit is contained in:
parent
f6c60b41dd
commit
dd444bf233
3 changed files with 33 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
JAWG_API_KEY="Votre clé d'API jawg.io"
|
||||
HOST="0.0.0.0"
|
||||
PORT=5000
|
||||
TIMEZONE="Europe/Paris"
|
||||
|
||||
# Monitoring
|
||||
monitoring_enabled=false
|
||||
|
|
15
app.py
15
app.py
|
@ -1,6 +1,7 @@
|
|||
from flask import Flask, render_template, request
|
||||
from flask import Flask, render_template, request, redirect, url_for
|
||||
from datetime import timedelta
|
||||
from dotenv import load_dotenv
|
||||
from zoneinfo import ZoneInfo
|
||||
from threading import Thread
|
||||
from os import getenv
|
||||
import html
|
||||
|
@ -17,6 +18,7 @@ theaters = [Theater(data["node"]) for data in
|
|||
|
||||
theaters += [Theater(data["node"]) for data in requests.get("https://www.allocine.fr/_/localization_city/Landerneau").json()["values"]["theaters"]]
|
||||
|
||||
timezone = ZoneInfo(getenv("TIMEZONE"))
|
||||
|
||||
def getShowtimes(date):
|
||||
showtimes: list[Showtime] = []
|
||||
|
@ -58,7 +60,7 @@ def getShowtimes(date):
|
|||
|
||||
showtimes = []
|
||||
for i in range(0, 7):
|
||||
day_showtimes = getShowtimes(datetime.today() + timedelta(days=i))
|
||||
day_showtimes = getShowtimes(datetime.now(timezone) + timedelta(days=i))
|
||||
showtimes.append(day_showtimes)
|
||||
print(f"{len(day_showtimes)} séances récupéré {i + 1}/7!")
|
||||
|
||||
|
@ -80,6 +82,10 @@ app = Flask(__name__)
|
|||
def healthcheck():
|
||||
return 'ok'
|
||||
|
||||
@app.route('/<int:day>')
|
||||
def special_day(day:int):
|
||||
return redirect(url_for("home", delta=day))
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
delta = request.args.get("delta", default=0, type=int)
|
||||
|
@ -95,12 +101,13 @@ def home():
|
|||
}).start()
|
||||
|
||||
if useragent.startswith("curl/"):
|
||||
return handle_curl(showtimes[delta])
|
||||
day = datetime.now(timezone) + timedelta(delta)
|
||||
return handle_curl(showtimes[delta], f"{day.day} {translate_month(day.month)}")
|
||||
|
||||
dates = []
|
||||
|
||||
for i in range(0, 7):
|
||||
day = datetime.today() + timedelta(i)
|
||||
day = datetime.now(timezone) + timedelta(i)
|
||||
dates.append({
|
||||
"jour": translate_day(day.weekday()),
|
||||
"chiffre": day.day,
|
||||
|
|
|
@ -2,19 +2,32 @@ border_top = "╔" + "═" * 58 + "╗"
|
|||
border_bottom = "╚" + "═" * 58 + "╝"
|
||||
separator = "╠" + "═" * 58 + "╣"
|
||||
|
||||
def handle_curl(movies):
|
||||
table = [border_top, "║{:^58}║".format("CinéBrest"), separator]
|
||||
def handle_curl(movies, day):
|
||||
table = [border_top,
|
||||
"║{:^58}║".format("CinéBrest"),
|
||||
"║{:^58}║".format(day),
|
||||
separator]
|
||||
|
||||
for film in movies:
|
||||
title_line = f"║ {film['title']:<57}║"
|
||||
table.append(title_line)
|
||||
|
||||
|
||||
for cinema, seances in film['seances'].items():
|
||||
cinema_line = f"║ ├─ {cinema:<54}║"
|
||||
seances_line = f"║ │ └─ : {', '.join(seances):<43}║"
|
||||
table.extend([cinema_line, seances_line])
|
||||
|
||||
table.append(cinema_line)
|
||||
|
||||
# Split seances into groups of 6
|
||||
groups = [seances[i:i+6] for i in range(0, len(seances), 6)]
|
||||
|
||||
for i, chunk in enumerate(groups):
|
||||
# Use └ for last group, ├ for others
|
||||
if i == len(groups) - 1:
|
||||
seances_line = f"║ │ └─ {', '.join(chunk):<45}║"
|
||||
else:
|
||||
seances_line = f"║ │ ├─ {', '.join(chunk):<45}║"
|
||||
table.append(seances_line)
|
||||
|
||||
table.append(separator)
|
||||
|
||||
|
||||
table[-1] = border_bottom
|
||||
return "\n".join(table)
|
||||
return "\n".join(table)+"\n"
|
Loading…
Reference in a new issue