mirror of
https://github.com/MathiasDPX/grainParisArt.git
synced 2025-01-08 16:16:40 +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"
|
JAWG_API_KEY="Votre clé d'API jawg.io"
|
||||||
HOST="0.0.0.0"
|
HOST="0.0.0.0"
|
||||||
PORT=5000
|
PORT=5000
|
||||||
|
TIMEZONE="Europe/Paris"
|
||||||
|
|
||||||
# Monitoring
|
# Monitoring
|
||||||
monitoring_enabled=false
|
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 datetime import timedelta
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from os import getenv
|
from os import getenv
|
||||||
import html
|
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"]]
|
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):
|
def getShowtimes(date):
|
||||||
showtimes: list[Showtime] = []
|
showtimes: list[Showtime] = []
|
||||||
|
@ -58,7 +60,7 @@ def getShowtimes(date):
|
||||||
|
|
||||||
showtimes = []
|
showtimes = []
|
||||||
for i in range(0, 7):
|
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)
|
showtimes.append(day_showtimes)
|
||||||
print(f"{len(day_showtimes)} séances récupéré {i + 1}/7!")
|
print(f"{len(day_showtimes)} séances récupéré {i + 1}/7!")
|
||||||
|
|
||||||
|
@ -80,6 +82,10 @@ app = Flask(__name__)
|
||||||
def healthcheck():
|
def healthcheck():
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
@app.route('/<int:day>')
|
||||||
|
def special_day(day:int):
|
||||||
|
return redirect(url_for("home", delta=day))
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
delta = request.args.get("delta", default=0, type=int)
|
delta = request.args.get("delta", default=0, type=int)
|
||||||
|
@ -95,12 +101,13 @@ def home():
|
||||||
}).start()
|
}).start()
|
||||||
|
|
||||||
if useragent.startswith("curl/"):
|
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 = []
|
dates = []
|
||||||
|
|
||||||
for i in range(0, 7):
|
for i in range(0, 7):
|
||||||
day = datetime.today() + timedelta(i)
|
day = datetime.now(timezone) + timedelta(i)
|
||||||
dates.append({
|
dates.append({
|
||||||
"jour": translate_day(day.weekday()),
|
"jour": translate_day(day.weekday()),
|
||||||
"chiffre": day.day,
|
"chiffre": day.day,
|
||||||
|
|
|
@ -2,8 +2,11 @@ border_top = "╔" + "═" * 58 + "╗"
|
||||||
border_bottom = "╚" + "═" * 58 + "╝"
|
border_bottom = "╚" + "═" * 58 + "╝"
|
||||||
separator = "╠" + "═" * 58 + "╣"
|
separator = "╠" + "═" * 58 + "╣"
|
||||||
|
|
||||||
def handle_curl(movies):
|
def handle_curl(movies, day):
|
||||||
table = [border_top, "║{:^58}║".format("CinéBrest"), separator]
|
table = [border_top,
|
||||||
|
"║{:^58}║".format("CinéBrest"),
|
||||||
|
"║{:^58}║".format(day),
|
||||||
|
separator]
|
||||||
|
|
||||||
for film in movies:
|
for film in movies:
|
||||||
title_line = f"║ {film['title']:<57}║"
|
title_line = f"║ {film['title']:<57}║"
|
||||||
|
@ -11,10 +14,20 @@ def handle_curl(movies):
|
||||||
|
|
||||||
for cinema, seances in film['seances'].items():
|
for cinema, seances in film['seances'].items():
|
||||||
cinema_line = f"║ ├─ {cinema:<54}║"
|
cinema_line = f"║ ├─ {cinema:<54}║"
|
||||||
seances_line = f"║ │ └─ : {', '.join(seances):<43}║"
|
table.append(cinema_line)
|
||||||
table.extend([cinema_line, seances_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.append(separator)
|
||||||
|
|
||||||
table[-1] = border_bottom
|
table[-1] = border_bottom
|
||||||
return "\n".join(table)
|
return "\n".join(table)+"\n"
|
Loading…
Reference in a new issue