Commit fb7d3fa013

fb7d3fa013e369ad550f718a1ee02867e1394d41

parent: a9eacfe6f9

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-21 23:48 UTC

update anime progress function added

Layout: unified · split

anilist.py +33
@@ -104,6 +104,39 @@ def search_anime_by_title(json_data, search_title):
104104
105105 return results
106106
107def 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
107140def main():
108141 # Load the JSON file
109142 json_file_path = 'response.json' # Replace with the path to your JSON file