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):
137137 else:
138138 print(f"Error {response.status_code}: {response.text}")
139139
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
140175def main():
141176 # Load the JSON file
142177 json_file_path = 'response.json' # Replace with the path to your JSON file
curd.py +1 −3
@@ -13,7 +13,7 @@ import subprocess
1313import time
1414
1515from 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
1717from select_link import load_links
1818from start_video import start_video, send_command, get_percentage_watched, percentage_watched, get_mpv_playback_speed
1919from select_anime import load_anime_data
@@ -243,7 +243,6 @@ else: # if there is no history
243243 else:
244244 print("Starting last episode of anime")
245245 progress = last_episode - 1
246
247246 watching_ep = int(progress)+1
248247 write_to_tmp("ep_no", str(watching_ep))
249248
@@ -370,7 +369,6 @@ while True:
370369 update_anime_progress(access_token, int(media_id), int(watching_ep))
371370 rate_anime(access_token, media_id, anime_rating_by_user)
372371 print("completed anime.")
373 # TODO: Add way to rate the anime
374372 delete_anime(user_config['history_file'], media_id, get_contents_of("id"))
375373 exit(0)
376374