Commit 3cabba3a70

3cabba3a70b58547fdd45dbbf1573342086d73b5

parent: daded0b1a9

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-24 20:06 UTC

get anime image function added

Layout: unified · split

anilist.py +24
@@ -101,6 +101,30 @@ def add_anime_to_watching_list(anime_id: int, token: str):
101101 else:
102102 print(f"Failed to add anime. Status Code: {response.status_code}, Response: {response.text}")
103103
104def 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}")
104128
105129def get_user_data(access_token, user_id):
106130# Replace with your actual access token and user ID