From caa1b0a3b0c92e5f9609be31646a79caacccf785 Mon Sep 17 00:00:00 2001 From: Benex254 Date: Mon, 5 Aug 2024 09:47:04 +0300 Subject: [PATCH] feat(anilist_api): handle none 200 status code --- fastanime/libs/anilist/api.py | 11 ++++- fastanime/libs/anilist/queries_graphql.py | 56 +++++++++++++++++------ 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/fastanime/libs/anilist/api.py b/fastanime/libs/anilist/api.py index 49a7d88..4cc767c 100644 --- a/fastanime/libs/anilist/api.py +++ b/fastanime/libs/anilist/api.py @@ -98,7 +98,10 @@ class AniListApi: headers=self.headers, ) anilist_data = response.json() - return (True, anilist_data) + if response.status_code == 200: + return (True, anilist_data) + else: + return (False, anilist_data) except requests.exceptions.Timeout: return ( False, @@ -142,7 +145,11 @@ class AniListApi: timeout=10, ) anilist_data: AnilistDataSchema = response.json() - return (True, anilist_data) + + if response.status_code == 200: + return (True, anilist_data) + else: + return (False, anilist_data) except requests.exceptions.Timeout: return ( False, diff --git a/fastanime/libs/anilist/queries_graphql.py b/fastanime/libs/anilist/queries_graphql.py index 172472f..bdbbfc0 100644 --- a/fastanime/libs/anilist/queries_graphql.py +++ b/fastanime/libs/anilist/queries_graphql.py @@ -9,30 +9,56 @@ mutation{ unreadNotificationCount } } +""" +reviews_query = """ +query($id:Int){ + Page{ + pageInfo{ + total + } + + reviews(mediaId:$id){ + summary + user{ + name + avatar { + large + medium + } + } + body + + } + } +} + """ notification_query = """ query{ Page { pageInfo { - total + total } notifications(resetNotificationCount:true,type:AIRING) { - ... on AiringNotification { - id - type - episode - contexts - createdAt - media { - id - title { - romaji - english - } + ... on AiringNotification { + id + type + episode + contexts + createdAt + media { + id + title { + romaji + english + } + coverImage{ + medium + } + } } } - } - } + } } """