From dd444bf233f23dc99060a658842fbd223943eca4 Mon Sep 17 00:00:00 2001 From: MathiasDPX Date: Tue, 31 Dec 2024 12:53:08 +0100 Subject: [PATCH] multiples fixes --- .env.example | 1 + app.py | 15 +++++++++++---- modules/curl.py | 29 +++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index ea8bf11..65a4962 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/app.py b/app.py index 7bcbd4a..de49d13 100644 --- a/app.py +++ b/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('/') +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, diff --git a/modules/curl.py b/modules/curl.py index 00013b4..212cffa 100644 --- a/modules/curl.py +++ b/modules/curl.py @@ -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) \ No newline at end of file + return "\n".join(table)+"\n" \ No newline at end of file