Commit bd98e60b56

bd98e60b56b7595b99729c45ef1ba397bf29761c

parent: 91e1ba304a

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-12 22:20 UTC

response kyeboard interrupt exception added

Layout: unified · split

curd.py +43 −20
@@ -122,9 +122,12 @@ def search_anime_anilist(query, token):
122122 'Authorization': f'Bearer {token}',
123123 'Content-Type': 'application/json'
124124 }
125 try:
126 response = requests.post(url, json={'query': query_string, 'variables': variables}, headers=headers)
127 except KeyboardInterrupt:
128 print("bye")
129 exit(0)
125130
126 response = requests.post(url, json={'query': query_string, 'variables': variables}, headers=headers)
127
128131 if response.status_code == 200:
129132 anime_list = response.json()['data']['Page']['media']
130133 anime_dict = {}
@@ -155,9 +158,12 @@ def get_anilist_user_id(token):
155158 "Content-Type": "application/json",
156159 "Accept": "application/json"
157160 }
158
159 response = requests.post(url, json={"query": query}, headers=headers)
160
161 try:
162 response = requests.post(url, json={"query": query}, headers=headers)
163 except KeyboardInterrupt:
164 print("bye")
165 exit(0)
166
161167 if response.status_code == 200:
162168 data = response.json()
163169 user_id = data['data']['Viewer']['id']
@@ -186,8 +192,11 @@ def add_anime_to_watching_list(anime_id: int, token: str):
186192 'Authorization': f'Bearer {token}',
187193 'Content-Type': 'application/json'
188194 }
189
190 response = requests.post(url, json={'query': mutation, 'variables': variables}, headers=headers)
195 try:
196 response = requests.post(url, json={'query': mutation, 'variables': variables}, headers=headers)
197 except KeyboardInterrupt:
198 print("bye")
199 exit(0)
191200
192201 if response.status_code == 200:
193202 print(f"Anime with ID {anime_id} has been added to your watching list.")
@@ -208,8 +217,12 @@ def get_anime_mal_id(anilist_media_id):
208217 }
209218
210219 # Make the API request
211 response = requests.post(url, json={'query': query, 'variables': variables})
212
220 try:
221 response = requests.post(url, json={'query': query, 'variables': variables})
222 except KeyboardInterrupt:
223 print("bye")
224 exit(0)
225
213226 if response.status_code == 200:
214227 data = response.json()
215228 malId = data['data']['Media']['idMal']
@@ -234,8 +247,11 @@ def get_anime_id_and_image(anilist_media_id):
234247 }
235248
236249 # Make the API request
237 response = requests.post(url, json={'query': query, 'variables': variables})
238
250 try:
251 response = requests.post(url, json={'query': query, 'variables': variables})
252 except KeyboardInterrupt:
253 print("bye")
254 exit(0)
239255 if response.status_code == 200:
240256 data = response.json()
241257 image_url = data['data']['Media']['coverImage']['large']
@@ -269,11 +285,15 @@ def get_user_data(access_token, user_id):
269285 """ % user_id
270286
271287 # Send the request
272 response = requests.post(
273 'https://graphql.anilist.co',
274 json={'query': query},
275 headers={'Authorization': f'Bearer {access_token}'}
276 )
288 try:
289 response = requests.post(
290 'https://graphql.anilist.co',
291 json={'query': query},
292 headers={'Authorization': f'Bearer {access_token}'}
293 )
294 except KeyboardInterrupt:
295 print("bye")
296 exit(0)
277297
278298
279299 # Print the response
@@ -334,9 +354,12 @@ def update_anime_progress(token: str, media_id: int, progress: int):
334354 "Content-Type": "application/json",
335355 "Accept": "application/json"
336356 }
337
338 response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)
339
357 try:
358 response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)
359 except KeyboardInterrupt:
360 print("bye")
361 exit(0)
362
340363 if response.status_code == 200:
341364 data = response.json()
342365 updated_progress = data['data']['SaveMediaListEntry']['progress']
@@ -473,7 +496,7 @@ def select_anime(anime_list):
473496 curses.endwin()
474497 print("Have a great day!")
475498 os._exit(0)
476
499
477500 # Handle key inputs
478501 if key in [curses.KEY_BACKSPACE, 127, 8]:
479502 current_input = current_input[:-1]