2024-09-16 11:29:02 +00:00
|
|
|
from flask import Flask, render_template, request
|
2024-10-09 17:15:56 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from os import getenv
|
2024-09-16 11:29:02 +00:00
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
# IMPORT DES MODULES
|
2024-09-18 16:41:31 +00:00
|
|
|
from modules.Classes import *
|
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
theaters = [Theater(data["node"]) for data in
|
|
|
|
requests.get("https://www.allocine.fr/_/localization_city/Brest").json()["values"]["theaters"]]
|
|
|
|
|
2024-09-18 16:41:31 +00:00
|
|
|
|
|
|
|
def getShowtimes(date):
|
2024-10-09 17:15:56 +00:00
|
|
|
showtimes: list[Showtime] = []
|
2024-09-18 16:41:31 +00:00
|
|
|
|
|
|
|
for theater in theaters:
|
|
|
|
showtimes.extend(theater.getShowtimes(date))
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
|
|
|
|
for showtime in showtimes:
|
|
|
|
movie = showtime.movie
|
|
|
|
theater = showtime.theater
|
|
|
|
|
|
|
|
if showtime.movie.title not in data.keys():
|
|
|
|
data[movie.title] = {
|
|
|
|
"title": movie.title,
|
|
|
|
"duree": movie.runtime,
|
|
|
|
"genres": ", ".join(movie.genres),
|
|
|
|
"casting": ", ".join(movie.cast),
|
|
|
|
"realisateur": movie.director,
|
|
|
|
"synopsis": movie.synopsis,
|
|
|
|
"affiche": movie.affiche,
|
|
|
|
"director": movie.director,
|
2024-09-18 18:32:49 +00:00
|
|
|
"wantToSee": movie.wantToSee,
|
|
|
|
"url": f"https://www.allocine.fr/film/fichefilm_gen_cfilm={movie.id}.html",
|
2024-09-18 16:41:31 +00:00
|
|
|
"seances": {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if theater.name not in data[movie.title]["seances"].keys():
|
|
|
|
data[movie.title]["seances"][theater.name] = []
|
|
|
|
|
|
|
|
data[movie.title]["seances"][theater.name].append(showtime.startsAt.strftime("%H:%M"))
|
|
|
|
|
2024-09-18 18:32:49 +00:00
|
|
|
data = data.values()
|
|
|
|
|
|
|
|
data = sorted(data, key=lambda x: x["wantToSee"], reverse=True)
|
|
|
|
|
2024-09-18 16:41:31 +00:00
|
|
|
return data
|
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
|
2024-09-18 16:55:11 +00:00
|
|
|
showtimes = []
|
|
|
|
for i in range(0, 7):
|
2024-10-09 17:15:56 +00:00
|
|
|
day_showtimes = getShowtimes(datetime.today() + timedelta(days=i))
|
2024-09-19 18:22:41 +00:00
|
|
|
showtimes.append(day_showtimes)
|
2024-10-09 17:15:56 +00:00
|
|
|
print(f"{len(day_showtimes)} séances récupéré {i + 1}/7!")
|
2024-09-18 16:41:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def translateMonth(num: int):
|
|
|
|
match num:
|
|
|
|
case 1: return "janv"
|
|
|
|
case 2: return "févr"
|
|
|
|
case 3: return "mars"
|
|
|
|
case 4: return "avr"
|
|
|
|
case 5: return "mai"
|
|
|
|
case 6: return "juin"
|
|
|
|
case 7: return "juil"
|
|
|
|
case 8: return "août"
|
|
|
|
case 9: return "sept"
|
|
|
|
case 10: return "oct"
|
|
|
|
case 11: return "nov"
|
|
|
|
case 12: return "déc"
|
|
|
|
case _: return "???"
|
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
|
2024-09-18 16:41:31 +00:00
|
|
|
def translateDay(weekday: int):
|
|
|
|
match weekday:
|
|
|
|
case 0: return "lun"
|
|
|
|
case 1: return "mar"
|
|
|
|
case 2: return "mer"
|
|
|
|
case 3: return "jeu"
|
|
|
|
case 4: return "ven"
|
|
|
|
case 5: return "sam"
|
|
|
|
case 6: return "dim"
|
|
|
|
case _: return "???"
|
2024-09-16 11:29:02 +00:00
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2024-09-16 11:29:02 +00:00
|
|
|
@app.route('/')
|
|
|
|
def home():
|
2024-09-18 16:41:31 +00:00
|
|
|
delta = request.args.get("delta", default=0, type=int)
|
2024-09-16 11:29:02 +00:00
|
|
|
|
2024-09-18 16:41:31 +00:00
|
|
|
if delta > 6: delta = 6
|
|
|
|
if delta < 0: delta = 0
|
2024-09-16 11:29:02 +00:00
|
|
|
|
2024-09-18 16:41:31 +00:00
|
|
|
dates = []
|
2024-09-16 11:29:02 +00:00
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
for i in range(0, 7):
|
|
|
|
day = datetime.today() + timedelta(i)
|
2024-09-18 16:41:31 +00:00
|
|
|
dates.append({
|
|
|
|
"jour": translateDay(day.weekday()),
|
|
|
|
"chiffre": day.day,
|
|
|
|
"mois": translateMonth(day.month),
|
2024-10-09 17:15:56 +00:00
|
|
|
"choisi": i == delta,
|
2024-09-18 16:41:31 +00:00
|
|
|
"index": i
|
|
|
|
})
|
2024-09-16 11:29:02 +00:00
|
|
|
|
2024-10-09 17:15:56 +00:00
|
|
|
return render_template('index.html',
|
|
|
|
films=showtimes[delta],
|
|
|
|
dates=dates,
|
|
|
|
JAWG_API_KEY=getenv("JAWG_API_KEY"))
|
2024-09-16 11:29:02 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-10-19 12:47:30 +00:00
|
|
|
app.run(host=getenv("HOST"), port=getenv("PORT"))
|