diff options
| author | Bobby <[email protected]> | 2024-10-06 01:34:45 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-10-06 01:34:45 -0400 |
| commit | baeebfad03e243bc2598fa7cf9195a03e5d130ae (patch) | |
| tree | e917fcbfa69098cbfd193135ddd232390872761e /read | |
| parent | 90ad24fbb0ae7f2bfa9b84ab1dbae296610012f8 (diff) | |
| download | yugen-baeebfad03e243bc2598fa7cf9195a03e5d130ae.tar.xz yugen-baeebfad03e243bc2598fa7cf9195a03e5d130ae.zip | |
Manga Detail Page
Diffstat (limited to 'read')
| -rw-r--r-- | read/utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
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 |
