Commit 6a435fba39

6a435fba39e891b784cb19aec667a301029c7714

parent: 3ea063d037

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-25 13:03 UTC

trying to implement try DRY

Layout: unified · split

curd.py +25 −1
@@ -190,7 +190,30 @@ def add_anime_to_watching_list(anime_id: int, token: str):
190190 else:
191191 print(f"Failed to add anime. Status Code: {response.status_code}, Response: {response.text}")
192192
193def get_anime_image(anilist_media_id):
193def get_anime_mal_id(anilist_media_id):
194 url = "https://graphql.anilist.co"
195 query = '''
196 query ($id: Int) {
197 Media(id: $id) {
198 idMal
199 }
200 }
201 '''
202 variables = {
203 'id': anilist_media_id
204 }
205
206 # Make the API request
207 response = requests.post(url, json={'query': query, 'variables': variables})
208
209 if response.status_code == 200:
210 data = response.json()
211 malId = data['data']['Media']['idMal']
212 return malId
213 else:
214 raise Exception(f"Failed to retrieve data from AniList API. Status Code: {response.status_code}")
215
216def get_anime_id_and_image(anilist_media_id):
194217 url = "https://graphql.anilist.co"
195218 query = '''
196219 query ($id: Int) {
@@ -198,6 +221,7 @@ def get_anime_image(anilist_media_id):
198221 coverImage {
199222 large
200223 }
224 idMal
201225 }
202226 }
203227 '''