From ff67b65ab341712e27396a919ba47ca6acf0c00b Mon Sep 17 00:00:00 2001 From: MathiasDPX Date: Wed, 18 Sep 2024 21:15:05 +0200 Subject: [PATCH] Support for +15 movies --- modules/Classes.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/modules/Classes.py b/modules/Classes.py index 243544a..e06cefb 100644 --- a/modules/Classes.py +++ b/modules/Classes.py @@ -67,32 +67,39 @@ class Theater: def __repr__(self) -> str: return f"<{self.__class__.__name__} name={self.name}>" - def getShowtimes(self, date:datetime) -> list[Showtime]: + def getShowtimes(self, date: datetime, page: int = 1, showtimes: list = None) -> list[Showtime]: + if showtimes is None: + showtimes = [] + datestr = date.strftime("%Y-%m-%d") - r = requests.get(f"https://www.allocine.fr/_/showtimes/theater-{self.id}/d-{datestr}/") + r = requests.get(f"https://www.allocine.fr/_/showtimes/theater-{self.id}/d-{datestr}/p-{page}/") + if r.status_code != 200: - return {"error": True, "messag": r.status_code, "content": r.content} + raise Exception(f"Error: {r.status_code} - {r.content}") try: data = r.json() - except: - return {"error": True, "message": "Can't parse JSON", "content": r.content} + except Exception as e: + raise Exception(f"Can't parse JSON: {str(e)} - {r.content}") - if data['error']: - return {"error": True, "message": "Error in request", "content": data} - - showtimes = [] + if data["message"] == "no.showtime.error": + return [] + if data.get('error'): + raise Exception(f"API Error: {data}") + for movie in data['results']: inst = Movie(movie["movie"]) - movie_showtimes = [] - movie_showtimes.extend(movie["showtimes"]["dubbed"]) - movie_showtimes.extend(movie["showtimes"]["original"]) - movie_showtimes.extend(movie["showtimes"]["local"]) + movie_showtimes = movie["showtimes"].get("dubbed", []) + \ + movie["showtimes"].get("original", []) + \ + movie["showtimes"].get("local", []) for showtime_data in movie_showtimes: showtimes.append(Showtime(showtime_data, self, inst)) - + + if int(data['pagination']['page']) < int(data['pagination']["totalPages"]): + return self.getShowtimes(date, page + 1, showtimes) + return showtimes @staticmethod