From fdd4d8c92d5337dab92d028c6f67aeda2398cabe Mon Sep 17 00:00:00 2001 From: Wawa <66263633+wneel@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:33:29 +0200 Subject: [PATCH] feat: create date offset function to dynamically update cinema URLs --- app.py | 481 +++++++++------------------------------------------------ 1 file changed, 73 insertions(+), 408 deletions(-) diff --git a/app.py b/app.py index ee21d42..3cda80f 100644 --- a/app.py +++ b/app.py @@ -11,6 +11,71 @@ from modules.urlGenerator import decalageDate app = Flask(__name__) cache = Cache(app, config={'CACHE_TYPE': 'simple'}) +def format(cinema, nb): + return ({ + "salle": cinema["salle"], + "url": decalageDate(cinema["url"], nb) + }) + +cinemas_data = [ + { + "salle" : "Écoles Cinéma Club", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0071.html" + }, + { + "salle" : "MK2 Bibliothèque", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C2954.html", + }, + { + "salle" : "MK2 Beaubourg", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0050.html" + }, + { + "salle" : "Épée de bois", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=W7504.html" + }, + { + "salle" : "Cinéma du Panthéon", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0076.html" + }, + { + "salle" : "Max Linder Panorama", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0089.html" + }, + { + "salle" : "Luminor Hotel de Ville", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0013.html" + }, + { + "salle" : "Le Grand Action", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0072.html" + }, + { + "salle" : "MK2 Parnasse", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0099.html" + }, + { + "salle" : "Le Champo", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0073.html" + }, + { + "salle" : "Filmothèque du Quartier Latin", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0020.html" + }, + { + "salle" : "Reflet Medicis", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0074.html" + }, + { + "salle" : "UGC Ciné Cité Les Halles", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0159.html" + }, + { + "salle" : "UGC Ciné Cité Bercy", + "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0026.html" + } +] + @app.route('/') @cache.cached(timeout=3600) def home(): @@ -52,64 +117,7 @@ def home(): } } - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0071.html" - }, - { - "salle" : "MK2 Bibliothèque", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C2954.html", - }, - { - "salle" : "MK2 Beaubourg", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0050.html" - }, - { - "salle" : "Épée de bois", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=W7504.html" - }, - { - "salle" : "Cinéma du Panthéon", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0076.html" - }, - { - "salle" : "Max Linder Panorama", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0089.html" - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0013.html" - }, - { - "salle" : "Le Grand Action", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0072.html" - }, - { - "salle" : "MK2 Parnasse", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0099.html" - }, - { - "salle" : "Le Champo", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0073.html" - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0020.html" - }, - { - "salle" : "Reflet Medicis", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0074.html" - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0159.html" - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : "https://www.allocine.fr/seance/salle_gen_csalle=C0026.html" - } - ] + cinemas = cinemas_data; films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -160,64 +168,7 @@ def jour1(): films = [] - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0071.html#shwt_date=", 1) - }, - { - "salle" : "MK2 Bibliothèque", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C2954.html#shwt_date=l",1) - }, - { - "salle" : "MK2 Beaubourg", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0050.html#shwt_date=",1) - }, - { - "salle" : "Épée de bois", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=W7504.html#shwt_date=",1) - }, - { - "salle" : "Cinéma du Panthéon", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0076.html#shwt_date=",1) - }, - { - "salle" : "Max Linder Panorama", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0089.html#shwt_date=",1) - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0013.html#shwt_date=",1) - }, - { - "salle" : "Le Grand Action", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0072.html#shwt_date=",1) - }, - { - "salle" : "MK2 Parnasse", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0099.html#shwt_date=",1) - }, - { - "salle" : "Le Champo", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0073.html#shwt_date=",1) - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0020.html#shwt_date=",1) - }, - { - "salle" : "Reflet Medicis", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0074.html#shwt_date=",1) - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0159.html#shwt_date=",1) - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0026.html#shwt_date=",1) - } - ] + cinemas = list(map(lambda cinema: format(cinema, 1), cinemas)) films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -267,64 +218,7 @@ def jour2(): films = [] - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0071.html#shwt_date=", 2) - }, - { - "salle" : "MK2 Bibliothèque", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C2954.html#shwt_date=l",2) - }, - { - "salle" : "MK2 Beaubourg", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0050.html#shwt_date=",2) - }, - { - "salle" : "Épée de bois", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=W7504.html#shwt_date=",2) - }, - { - "salle" : "Cinéma du Panthéon", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0076.html#shwt_date=",2) - }, - { - "salle" : "Max Linder Panorama", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0089.html#shwt_date=",2) - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0013.html#shwt_date=",2) - }, - { - "salle" : "Le Grand Action", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0072.html#shwt_date=",2) - }, - { - "salle" : "MK2 Parnasse", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0099.html#shwt_date=",2) - }, - { - "salle" : "Le Champo", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0073.html#shwt_date=",2) - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0020.html#shwt_date=",2) - }, - { - "salle" : "Reflet Medicis", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0074.html#shwt_date=",2) - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0159.html#shwt_date=",2) - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0026.html#shwt_date=",2) - } - ] + cinemas = list(map(lambda cinema: format(cinema, 2), cinemas)) films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -374,64 +268,7 @@ def jour3(): films = [] - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0071.html#shwt_date=", 3) - }, - { - "salle" : "MK2 Bibliothèque", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C2954.html#shwt_date=l",3) - }, - { - "salle" : "MK2 Beaubourg", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0050.html#shwt_date=",3) - }, - { - "salle" : "Épée de bois", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=W7504.html#shwt_date=",3) - }, - { - "salle" : "Cinéma du Panthéon", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0076.html#shwt_date=",3) - }, - { - "salle" : "Max Linder Panorama", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0089.html#shwt_date=",3) - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0013.html#shwt_date=",3) - }, - { - "salle" : "Le Grand Action", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0072.html#shwt_date=",3) - }, - { - "salle" : "MK2 Parnasse", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0099.html#shwt_date=",3) - }, - { - "salle" : "Le Champo", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0073.html#shwt_date=",3) - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0020.html#shwt_date=",3) - }, - { - "salle" : "Reflet Medicis", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0074.html#shwt_date=",3) - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0159.html#shwt_date=",3) - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0026.html#shwt_date=",3) - } - ] + cinemas = list(map(lambda cinema: format(cinema, 3), cinemas)) films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -481,64 +318,7 @@ def jour4(): films = [] - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0071.html#shwt_date=", 4) - }, - { - "salle" : "MK2 Bibliothèque", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C2954.html#shwt_date=l",4) - }, - { - "salle" : "MK2 Beaubourg", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0050.html#shwt_date=",4) - }, - { - "salle" : "Épée de bois", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=W7504.html#shwt_date=",4) - }, - { - "salle" : "Cinéma du Panthéon", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0076.html#shwt_date=",4) - }, - { - "salle" : "Max Linder Panorama", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0089.html#shwt_date=",4) - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0013.html#shwt_date=",4) - }, - { - "salle" : "Le Grand Action", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0072.html#shwt_date=",4) - }, - { - "salle" : "MK2 Parnasse", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0099.html#shwt_date=",4) - }, - { - "salle" : "Le Champo", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0073.html#shwt_date=",4) - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0020.html#shwt_date=",4) - }, - { - "salle" : "Reflet Medicis", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0074.html#shwt_date=",4) - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0159.html#shwt_date=",4) - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0026.html#shwt_date=",4) - } - ] + cinemas = list(map(lambda cinema: format(cinema, 4), cinemas)) films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -588,65 +368,7 @@ def jour5(): films = [] - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0071.html#shwt_date=",5) - }, - { - "salle" : "MK2 Bibliothèque", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C2954.html#shwt_date=l",5) - }, - { - "salle" : "MK2 Beaubourg", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0050.html#shwt_date=",5) - }, - { - "salle" : "Épée de bois", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=W7504.html#shwt_date=",5) - }, - { - "salle" : "Cinéma du Panthéon", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0076.html#shwt_date=",5) - }, - { - "salle" : "Max Linder Panorama", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0089.html#shwt_date=",5) - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0013.html#shwt_date=",5) - }, - { - "salle" : "Le Grand Action", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0072.html#shwt_date=",5) - }, - { - "salle" : "MK2 Parnasse", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0099.html#shwt_date=",5) - }, - { - "salle" : "Le Champo", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0073.html#shwt_date=",5) - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0020.html#shwt_date=",5) - }, - { - "salle" : "Reflet Medicis", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0074.html#shwt_date=",5) - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0159.html#shwt_date=",5) - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0026.html#shwt_date=",5) - } - ] - + cinemas = list(map(lambda cinema: format(cinema, 5), cinemas)) films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -695,64 +417,7 @@ def jour6(): films = [] - cinemas = [ - { - "salle" : "Écoles Cinéma Club", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0071.html#shwt_date=", 6) - }, - { - "salle" : "MK2 Bibliothèque", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C2954.html#shwt_date=l",6) - }, - { - "salle" : "MK2 Beaubourg", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0050.html#shwt_date=",6) - }, - { - "salle" : "Épée de bois", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=W7504.html#shwt_date=",6) - }, - { - "salle" : "Cinéma du Panthéon", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0076.html#shwt_date=",6) - }, - { - "salle" : "Max Linder Panorama", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0089.html#shwt_date=",6) - }, - { - "salle" : "Luminor Hotel de Ville", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0013.html#shwt_date=",6) - }, - { - "salle" : "Le Grand Action", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0072.html#shwt_date=",6) - }, - { - "salle" : "MK2 Parnasse", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0099.html#shwt_date=",6) - }, - { - "salle" : "Le Champo", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0073.html#shwt_date=",6) - }, - { - "salle" : "Filmothèque du Quartier Latin", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0020.html#shwt_date=",6) - }, - { - "salle" : "Reflet Medicis", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0074.html#shwt_date=",6) - }, - { - "salle" : "UGC Ciné Cité Les Halles", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0159.html#shwt_date=",6) - }, - { - "salle" : "UGC Ciné Cité Bercy", - "url" : decalageDate("https://www.allocine.fr/seance/salle_gen_csalle=C0026.html#shwt_date=",6) - } - ] + cinemas = list(map(lambda cinema: format(cinema, 6), cinemas)) films = get_data(cinemas) filmsClean = cleanFilms(films) @@ -767,4 +432,4 @@ def process(): return jsonify(status='success', message='Traitement terminé') """ if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(debug=True)