diff --git a/src/common.py b/src/common.py index c9823d9..60a3890 100644 --- a/src/common.py +++ b/src/common.py @@ -1,16 +1,5 @@ from datetime import date -import jsonschema - - -def is_valid_schema(obj, schema: dict) -> bool: - result = True - try: - jsonschema.validate(instance=obj, schema=schema) - except jsonschema.ValidationError: - result = False - return result - def is_valid_date(given_date: str): result = True diff --git a/src/consts.py b/src/consts.py index 128345c..db1f025 100644 --- a/src/consts.py +++ b/src/consts.py @@ -2,1625 +2,4 @@ TMDB_BASE_IMG_URL = "image.tmdb.org/t/p/w500" TMDB_MCU_LIST = 140624 TMDB_LNG_DEFAULT = "en-CA" -TMDB_LIST_SCHEMA = { - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "created_by": { - "type": "string" - }, - "description": { - "type": "string" - }, - "favorite_count": { - "type": "integer" - }, - "id": { - "type": "integer" - }, - "iso_639_1": { - "type": "string" - }, - "item_count": { - "type": "integer" - }, - "items": { - "type": "array", - "items": [ - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - }, - { - "type": "object", - "properties": { - "adult": { - "type": "boolean" - }, - "backdrop_path": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "original_language": { - "type": "string" - }, - "original_title": { - "type": "string" - }, - "overview": { - "type": "string" - }, - "poster_path": { - "type": "string" - }, - "media_type": { - "type": "string" - }, - "genre_ids": { - "type": "array", - "items": [ - { - "type": "integer" - }, - { - "type": "integer" - }, - { - "type": "integer" - } - ] - }, - "popularity": { - "type": "number" - }, - "release_date": { - "type": "string" - }, - "video": { - "type": "boolean" - }, - "vote_average": { - "type": "number" - }, - "vote_count": { - "type": "integer" - } - }, - "required": [ - "adult", - "backdrop_path", - "id", - "title", - "original_language", - "original_title", - "overview", - "poster_path", - "media_type", - "genre_ids", - "popularity", - "release_date", - "video", - "vote_average", - "vote_count" - ] - } - ] - }, - "name": { - "type": "string" - }, - "page": { - "type": "integer" - }, - "poster_path": { - "type": "null" - }, - "total_pages": { - "type": "integer" - }, - "total_results": { - "type": "integer" - } - }, - "required": [ - "created_by", - "description", - "favorite_count", - "id", - "iso_639_1", - "item_count", - "items", - "name", - "page", - "poster_path", - "total_pages", - "total_results" - ] -} NOT_FOUND = 404 diff --git a/src/services/oracle.py b/src/services/oracle.py index dda7b7b..8a71ecc 100644 --- a/src/services/oracle.py +++ b/src/services/oracle.py @@ -18,15 +18,9 @@ def get_next_production( response = None if not production_list: - response = self.tmdb.get_list(TMDB_MCU_LIST) + response = self.tmdb.get_last_page_list(TMDB_MCU_LIST) if response: production_list = response["items"] - current_page = response["page"] - total_num_pages = response["total_pages"] - - if current_page < total_num_pages: - response = self.tmdb.get_list(TMDB_MCU_LIST, total_num_pages) - production_list = response["items"] if production_list: if not desired_date: diff --git a/src/services/tmdb.py b/src/services/tmdb.py index 54bfce1..66051a1 100644 --- a/src/services/tmdb.py +++ b/src/services/tmdb.py @@ -3,9 +3,7 @@ import requests -from src.common import is_valid_schema -from src.consts import (TMDB_BASE_IMG_URL, TMDB_BASE_URL, TMDB_LIST_SCHEMA, - TMDB_LNG_DEFAULT) +from src.consts import (TMDB_BASE_IMG_URL, TMDB_BASE_URL, TMDB_LNG_DEFAULT) class TMDBService: @@ -40,10 +38,25 @@ def get_list( page_num: int = 1 ) -> Optional[dict]: result = self.send_request("list/{}".format(list_num), page_num) - if result and is_valid_schema(result.json(), TMDB_LIST_SCHEMA): + if result: return result.json() return None + def get_last_page_list( + self, + list_num: int + ) -> Optional[dict]: + result = self.get_list(list_num) + + if result: + current_page = result["page"] + last_page = result["total_pages"] + + if current_page < last_page: + result = self.get_list(list_num, last_page) + + return result + def give_poster_url( self, path_to_img: str