Commit 386a3ede88
Unsigned
Layout: unified · split
anilist.py +32
| @@ -2,6 +2,38 @@ import requests | |||
| 2 | import json | 2 | import json |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | import requests | ||
| 6 | |||
| 7 | def get_anilist_user_id(token): | ||
| 8 | url = "https://graphql.anilist.co" | ||
| 9 | query = ''' | ||
| 10 | query { | ||
| 11 | Viewer { | ||
| 12 | id | ||
| 13 | name | ||
| 14 | } | ||
| 15 | } | ||
| 16 | ''' | ||
| 17 | |||
| 18 | headers = { | ||
| 19 | "Authorization": f"Bearer {token}", | ||
| 20 | "Content-Type": "application/json", | ||
| 21 | "Accept": "application/json" | ||
| 22 | } | ||
| 23 | |||
| 24 | response = requests.post(url, json={"query": query}, headers=headers) | ||
| 25 | |||
| 26 | if response.status_code == 200: | ||
| 27 | data = response.json() | ||
| 28 | user_id = data['data']['Viewer']['id'] | ||
| 29 | user_name = data['data']['Viewer']['name'] | ||
| 30 | return user_id, user_name | ||
| 31 | else: | ||
| 32 | raise Exception(f"Error: {response.status_code}, {response.text}") | ||
| 33 | |||
| 34 | # Replace 'your_token' with your actual AniList token | ||
| 35 | |||
| 36 | |||
| 5 | def get_user_data(access_token, user_id): | 37 | def get_user_data(access_token, user_id): |
| 6 | # Replace with your actual access token and user ID | 38 | # Replace with your actual access token and user ID |
| 7 | # access_token = | 39 | # access_token = |