Commit 3cabba3a70
Unsigned
Layout: unified · split
anilist.py +24
| @@ -101,6 +101,30 @@ def add_anime_to_watching_list(anime_id: int, token: str): | ||
| 101 | 101 | else: |
| 102 | 102 | print(f"Failed to add anime. Status Code: {response.status_code}, Response: {response.text}") |
| 103 | 103 | |
| 104 | def get_anime_image(anilist_media_id): | |
| 105 | url = "https://graphql.anilist.co" | |
| 106 | query = ''' | |
| 107 | query ($id: Int) { | |
| 108 | Media(id: $id) { | |
| 109 | coverImage { | |
| 110 | large | |
| 111 | } | |
| 112 | } | |
| 113 | } | |
| 114 | ''' | |
| 115 | variables = { | |
| 116 | 'id': anilist_media_id | |
| 117 | } | |
| 118 | ||
| 119 | # Make the API request | |
| 120 | response = requests.post(url, json={'query': query, 'variables': variables}) | |
| 121 | ||
| 122 | if response.status_code == 200: | |
| 123 | data = response.json() | |
| 124 | image_url = data['data']['Media']['coverImage']['large'] | |
| 125 | return image_url | |
| 126 | else: | |
| 127 | raise Exception(f"Failed to retrieve data from AniList API. Status Code: {response.status_code}") | |
| 104 | 128 | |
| 105 | 129 | def get_user_data(access_token, user_id): |
| 106 | 130 | # Replace with your actual access token and user ID |