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):
122 'Authorization': f'Bearer {token}', 122 'Authorization': f'Bearer {token}',
123 'Content-Type': 'application/json' 123 'Content-Type': 'application/json'
124 } 124 }
125 try:
126 response = requests.post(url, json={'query': query_string, 'variables': variables}, headers=headers)
127 except KeyboardInterrupt:
128 print("bye")
129 exit(0)
125 130
126 response = requests.post(url, json={'query': query_string, 'variables': variables}, headers=headers)
127
128 if response.status_code == 200: 131 if response.status_code == 200:
129 anime_list = response.json()['data']['Page']['media'] 132 anime_list = response.json()['data']['Page']['media']
130 anime_dict = {} 133 anime_dict = {}
@@ -155,9 +158,12 @@ def get_anilist_user_id(token):
155 "Content-Type": "application/json", 158 "Content-Type": "application/json",
156 "Accept": "application/json" 159 "Accept": "application/json"
157 } 160 }
158 161 try:
159 response = requests.post(url, json={"query": query}, headers=headers) 162 response = requests.post(url, json={"query": query}, headers=headers)
160 163 except KeyboardInterrupt:
164 print("bye")
165 exit(0)
166
161 if response.status_code == 200: 167 if response.status_code == 200:
162 data = response.json() 168 data = response.json()
163 user_id = data['data']['Viewer']['id'] 169 user_id = data['data']['Viewer']['id']
@@ -186,8 +192,11 @@ def add_anime_to_watching_list(anime_id: int, token: str):
186 'Authorization': f'Bearer {token}', 192 'Authorization': f'Bearer {token}',
187 'Content-Type': 'application/json' 193 'Content-Type': 'application/json'
188 } 194 }
189 195 try:
190 response = requests.post(url, json={'query': mutation, 'variables': variables}, headers=headers) 196 response = requests.post(url, json={'query': mutation, 'variables': variables}, headers=headers)
197 except KeyboardInterrupt:
198 print("bye")
199 exit(0)
191 200
192 if response.status_code == 200: 201 if response.status_code == 200:
193 print(f"Anime with ID {anime_id} has been added to your watching list.") 202 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):
208 } 217 }
209 218
210 # Make the API request 219 # Make the API request
211 response = requests.post(url, json={'query': query, 'variables': variables}) 220 try:
212 221 response = requests.post(url, json={'query': query, 'variables': variables})
222 except KeyboardInterrupt:
223 print("bye")
224 exit(0)
225
213 if response.status_code == 200: 226 if response.status_code == 200:
214 data = response.json() 227 data = response.json()
215 malId = data['data']['Media']['idMal'] 228 malId = data['data']['Media']['idMal']
@@ -234,8 +247,11 @@ def get_anime_id_and_image(anilist_media_id):
234 } 247 }
235 248
236 # Make the API request 249 # Make the API request
237 response = requests.post(url, json={'query': query, 'variables': variables}) 250 try:
238 251 response = requests.post(url, json={'query': query, 'variables': variables})
252 except KeyboardInterrupt:
253 print("bye")
254 exit(0)
239 if response.status_code == 200: 255 if response.status_code == 200:
240 data = response.json() 256 data = response.json()
241 image_url = data['data']['Media']['coverImage']['large'] 257 image_url = data['data']['Media']['coverImage']['large']
@@ -269,11 +285,15 @@ def get_user_data(access_token, user_id):
269 """ % user_id 285 """ % user_id
270 286
271 # Send the request 287 # Send the request
272 response = requests.post( 288 try:
273 'https://graphql.anilist.co', 289 response = requests.post(
274 json={'query': query}, 290 'https://graphql.anilist.co',
275 headers={'Authorization': f'Bearer {access_token}'} 291 json={'query': query},
276 ) 292 headers={'Authorization': f'Bearer {access_token}'}
293 )
294 except KeyboardInterrupt:
295 print("bye")
296 exit(0)
277 297
278 298
279 # Print the response 299 # Print the response
@@ -334,9 +354,12 @@ def update_anime_progress(token: str, media_id: int, progress: int):
334 "Content-Type": "application/json", 354 "Content-Type": "application/json",
335 "Accept": "application/json" 355 "Accept": "application/json"
336 } 356 }
337 357 try:
338 response = requests.post(url, json={"query": query, "variables": variables}, headers=headers) 358 response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)
339 359 except KeyboardInterrupt:
360 print("bye")
361 exit(0)
362
340 if response.status_code == 200: 363 if response.status_code == 200:
341 data = response.json() 364 data = response.json()
342 updated_progress = data['data']['SaveMediaListEntry']['progress'] 365 updated_progress = data['data']['SaveMediaListEntry']['progress']
@@ -473,7 +496,7 @@ def select_anime(anime_list):
473 curses.endwin() 496 curses.endwin()
474 print("Have a great day!") 497 print("Have a great day!")
475 os._exit(0) 498 os._exit(0)
476 499
477 # Handle key inputs 500 # Handle key inputs
478 if key in [curses.KEY_BACKSPACE, 127, 8]: 501 if key in [curses.KEY_BACKSPACE, 127, 8]:
479 current_input = current_input[:-1] 502 current_input = current_input[:-1]