From baeebfad03e243bc2598fa7cf9195a03e5d130ae Mon Sep 17 00:00:00 2001 From: Bobby Date: Sun, 6 Oct 2024 01:34:45 -0400 Subject: Manga Detail Page --- read/utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 read/utils.py (limited to 'read/utils.py') diff --git a/read/utils.py b/read/utils.py new file mode 100644 index 0000000..804c619 --- /dev/null +++ b/read/utils.py @@ -0,0 +1,30 @@ +import json +import os + +import requests +from watch.utils import get_from_redis_cache, store_in_redis_cache + + +def get_manga_data(manga_id): + print(f"Fetching manga data: ID={manga_id}") + + cache_key = f"manga_{manga_id}_manga_data" + manga_data = get_from_redis_cache(cache_key) + + if not manga_data: + base_url = f"{os.getenv('CONSUMET_URL')}/meta/anilist-manga/info/{manga_id}" + print(f"Trying URL: {base_url}") + response = requests.get(base_url, timeout=10) + manga_data = response.json() + + if "message" in manga_data: + return None + + if "status" in manga_data and manga_data["status"] == "Completed": + store_in_redis_cache(cache_key, json.dumps(manga_data), 3600 * 24 * 30) + else: + store_in_redis_cache(cache_key, json.dumps(manga_data), 3600 * 24) + else: + manga_data = json.loads(manga_data) + + return manga_data -- cgit v1.2.3