diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1d3e84b --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +JAWG_API_KEY="Votre clé d'API jawg.io" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4bfa70f..f7a54c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ -__pycache__/ +.env + +# IDE .vscode/ +.idea + +# Python +__pycache__/ .venv \ No newline at end of file diff --git a/app.py b/app.py index 80761cd..38221ba 100644 --- a/app.py +++ b/app.py @@ -1,36 +1,19 @@ from flask import Flask, render_template, request -from datetime import datetime, timedelta +from datetime import timedelta +from dotenv import load_dotenv +from os import getenv -# IMPORT DES MODULES +load_dotenv() + +# IMPORT DES MODULES from modules.Classes import * -cinemas = { - "C0071": "Écoles Cinéma Club", - "C2954": "MK2 Bibliothèque", - "C0050": "MK2 Beaubourg", - "W7504": "Épée de bois", - "C0076": "Cinéma du Panthéon", - "C0089": "Max Linder Panorama", - "C0013": "Luminor Hotel de Ville", - "C0072": "Le Grand Action", - "C0099": "MK2 Parnasse", - "C0073": "Le Champo", - "C0020": "Filmothèque du Quartier Latin", - "C0074": "Reflet Medicis", - "C0159": "UGC Ciné Cité Les Halles", - "C0026": "UGC Ciné Cité Bercy" -} +theaters = [Theater(data["node"]) for data in + requests.get("https://www.allocine.fr/_/localization_city/Brest").json()["values"]["theaters"]] -theaters: list[Theater] = [] -for id, name in cinemas.items(): - theaters.append(Theater({ - "name": name, - "internalId": id, - "location": None - })) def getShowtimes(date): - showtimes:list[Showtime] = [] + showtimes: list[Showtime] = [] for theater in theaters: showtimes.extend(theater.getShowtimes(date)) @@ -56,7 +39,6 @@ def getShowtimes(date): "seances": {} } - if theater.name not in data[movie.title]["seances"].keys(): data[movie.title]["seances"][theater.name] = [] @@ -68,13 +50,13 @@ def getShowtimes(date): return data + showtimes = [] for i in range(0, 7): - day_showtimes = getShowtimes(datetime.today()+timedelta(days=i)) + day_showtimes = getShowtimes(datetime.today() + timedelta(days=i)) 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!") -app = Flask(__name__) def translateMonth(num: int): match num: @@ -92,6 +74,7 @@ def translateMonth(num: int): case 12: return "déc" case _: return "???" + def translateDay(weekday: int): match weekday: case 0: return "lun" @@ -103,6 +86,9 @@ def translateDay(weekday: int): case 6: return "dim" case _: return "???" + +app = Flask(__name__) + @app.route('/') def home(): delta = request.args.get("delta", default=0, type=int) @@ -112,17 +98,20 @@ def home(): dates = [] - for i in range(0,7): - day = datetime.today()+timedelta(i) + for i in range(0, 7): + day = datetime.today() + timedelta(i) dates.append({ "jour": translateDay(day.weekday()), "chiffre": day.day, "mois": translateMonth(day.month), - "choisi": i==delta, + "choisi": i == delta, "index": i }) - return render_template('index.html', page_actuelle='home', films=showtimes[delta], dates=dates) + return render_template('index.html', + films=showtimes[delta], + dates=dates, + JAWG_API_KEY=getenv("JAWG_API_KEY")) if __name__ == '__main__': - app.run() + app.run() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0eb56cd..a704573 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask -requests \ No newline at end of file +requests +python-dotenv \ No newline at end of file diff --git a/static/images/favicon.png b/static/images/favicon.png index 2f0fde3..c3cb6ea 100644 Binary files a/static/images/favicon.png and b/static/images/favicon.png differ diff --git a/static/images/point.png b/static/images/point.png new file mode 100644 index 0000000..1ecbfba Binary files /dev/null and b/static/images/point.png differ diff --git a/static/js/infinite-scroll.js b/static/js/infinite-scroll.js deleted file mode 100644 index 6b6daab..0000000 --- a/static/js/infinite-scroll.js +++ /dev/null @@ -1,32 +0,0 @@ -var isLoading = false; -var page = 1; - -function fetchCinemaSessions() { - if (isLoading) return; - - isLoading = true; - var loadingContainer = document.getElementById('loading-container'); - loadingContainer.innerHTML = 'Loading...'; - - fetch('/?page=' + page) - .then(function(response) { - return response.text(); - }) - .then(function(html) { - var cinemaContainer = document.getElementById('cinema-container'); - cinemaContainer.insertAdjacentHTML('beforeend', html); - isLoading = false; - page += 1; - }) - .catch(function() { - isLoading = false; - }); -} - -window.addEventListener('scroll', function() { - if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100 && !isLoading) { - fetchCinemaSessions(); - } -}); - -fetchCinemaSessions(); diff --git a/templates/base.html b/templates/base.html index 72ea9bd..7940ecc 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,27 +4,31 @@ - - + + - grainParisArt + CinéBrest {% block head %} {% endblock %}
-

GrainParisArt

+

CinéBrest

Quand ça va pas, y aura toujours le cinéma

{% block body %} {% endblock %} - + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 050ffb5..8c56086 100644 --- a/templates/index.html +++ b/templates/index.html @@ -86,47 +86,32 @@ - -