Commit fb7d3fa013
Unsigned
Layout: unified · split
anilist.py +33
| @@ -104,6 +104,39 @@ def search_anime_by_title(json_data, search_title): | ||
| 104 | 104 | |
| 105 | 105 | return results |
| 106 | 106 | |
| 107 | def update_anime_progress(token: str, media_id: int, progress: int): | |
| 108 | url = "https://graphql.anilist.co" | |
| 109 | ||
| 110 | query = ''' | |
| 111 | mutation($mediaId: Int, $progress: Int) { | |
| 112 | SaveMediaListEntry(mediaId: $mediaId, progress: $progress) { | |
| 113 | id | |
| 114 | progress | |
| 115 | } | |
| 116 | } | |
| 117 | ''' | |
| 118 | ||
| 119 | variables = { | |
| 120 | "mediaId": media_id, # The AniList ID of the anime | |
| 121 | "progress": progress # The number of the latest episode you watched | |
| 122 | } | |
| 123 | ||
| 124 | headers = { | |
| 125 | "Authorization": f"Bearer {token}", | |
| 126 | "Content-Type": "application/json", | |
| 127 | "Accept": "application/json" | |
| 128 | } | |
| 129 | ||
| 130 | response = requests.post(url, json={"query": query, "variables": variables}, headers=headers) | |
| 131 | ||
| 132 | if response.status_code == 200: | |
| 133 | data = response.json() | |
| 134 | updated_progress = data['data']['SaveMediaListEntry']['progress'] | |
| 135 | print("updating progress..") | |
| 136 | print(f"Anime progress updated! Latest watched episode: {updated_progress}") | |
| 137 | else: | |
| 138 | print(f"Error {response.status_code}: {response.text}") | |
| 139 | ||
| 107 | 140 | def main(): |
| 108 | 141 | # Load the JSON file |
| 109 | 142 | json_file_path = 'response.json' # Replace with the path to your JSON file |