Commit cba084f08f

cba084f08fa2b983d166295d938d9fcfae341321

parent: 59ddb604d2

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-22 00:32 UTC

rate anime functionality added

Layout: unified · split

anilist.py +35
@@ -137,6 +137,41 @@ def update_anime_progress(token: str, media_id: int, progress: int):
137 else: 137 else:
138 print(f"Error {response.status_code}: {response.text}") 138 print(f"Error {response.status_code}: {response.text}")
139 139
140def rate_anime(anilist_token, media_id, score):
141 url = 'https://graphql.anilist.co'
142
143 # GraphQL mutation to rate anime
144 query = '''
145 mutation($mediaId: Int, $score: Float) {
146 SaveMediaListEntry(mediaId: $mediaId, score: $score) {
147 id
148 mediaId
149 score
150 }
151 }
152 '''
153
154 # Variables for the mutation
155 variables = {
156 "mediaId": media_id,
157 "score": float(score)
158 }
159
160 headers = {
161 "Authorization": f"Bearer {anilist_token}",
162 "Content-Type": "application/json",
163 }
164
165 response = requests.post(url, json={'query': query, 'variables': variables}, headers=headers)
166
167 if response.status_code == 200:
168 data = response.json()
169 print(f"Successfully rated anime (mediaId: {media_id}) with score: {score}")
170 return data
171 else:
172 print(f"Failed to rate anime. Status Code: {response.status_code}, Response: {response.text}")
173 return None
174
140def main(): 175def main():
141 # Load the JSON file 176 # Load the JSON file
142 json_file_path = 'response.json' # Replace with the path to your JSON file 177 json_file_path = 'response.json' # Replace with the path to your JSON file
curd.py +1 −3
@@ -13,7 +13,7 @@ import subprocess
13import time 13import time
14 14
15from anilist import search_anime_by_title 15from anilist import search_anime_by_title
16from anilist import get_user_data, get_anilist_user_id, update_anime_progress 16from anilist import get_user_data, get_anilist_user_id, update_anime_progress, rate_anime
17from select_link import load_links 17from select_link import load_links
18from start_video import start_video, send_command, get_percentage_watched, percentage_watched, get_mpv_playback_speed 18from start_video import start_video, send_command, get_percentage_watched, percentage_watched, get_mpv_playback_speed
19from select_anime import load_anime_data 19from select_anime import load_anime_data
@@ -243,7 +243,6 @@ else: # if there is no history
243 else: 243 else:
244 print("Starting last episode of anime") 244 print("Starting last episode of anime")
245 progress = last_episode - 1 245 progress = last_episode - 1
246
247 watching_ep = int(progress)+1 246 watching_ep = int(progress)+1
248 write_to_tmp("ep_no", str(watching_ep)) 247 write_to_tmp("ep_no", str(watching_ep))
249 248
@@ -370,7 +369,6 @@ while True:
370 update_anime_progress(access_token, int(media_id), int(watching_ep)) 369 update_anime_progress(access_token, int(media_id), int(watching_ep))
371 rate_anime(access_token, media_id, anime_rating_by_user) 370 rate_anime(access_token, media_id, anime_rating_by_user)
372 print("completed anime.") 371 print("completed anime.")
373 # TODO: Add way to rate the anime
374 delete_anime(user_config['history_file'], media_id, get_contents_of("id")) 372 delete_anime(user_config['history_file'], media_id, get_contents_of("id"))
375 exit(0) 373 exit(0)
376 374