Commit bd98e60b56
Unsigned
Layout: unified · split
curd.py +43 −20
| @@ -122,9 +122,12 @@ def search_anime_anilist(query, token): | ||
| 122 | 122 | 'Authorization': f'Bearer {token}', |
| 123 | 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 | 131 | if response.status_code == 200: |
| 129 | 132 | anime_list = response.json()['data']['Page']['media'] |
| 130 | 133 | anime_dict = {} |
| @@ -155,9 +158,12 @@ def get_anilist_user_id(token): | ||
| 155 | 158 | "Content-Type": "application/json", |
| 156 | 159 | "Accept": "application/json" |
| 157 | 160 | } |
| 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 | ||
| 161 | 167 | if response.status_code == 200: |
| 162 | 168 | data = response.json() |
| 163 | 169 | user_id = data['data']['Viewer']['id'] |
| @@ -186,8 +192,11 @@ def add_anime_to_watching_list(anime_id: int, token: str): | ||
| 186 | 192 | 'Authorization': f'Bearer {token}', |
| 187 | 193 | 'Content-Type': 'application/json' |
| 188 | 194 | } |
| 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) | |
| 191 | 200 | |
| 192 | 201 | if response.status_code == 200: |
| 193 | 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 | 219 | # 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 | ||
| 213 | 226 | if response.status_code == 200: |
| 214 | 227 | data = response.json() |
| 215 | 228 | malId = data['data']['Media']['idMal'] |
| @@ -234,8 +247,11 @@ def get_anime_id_and_image(anilist_media_id): | ||
| 234 | 247 | } |
| 235 | 248 | |
| 236 | 249 | # 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) | |
| 239 | 255 | if response.status_code == 200: |
| 240 | 256 | data = response.json() |
| 241 | 257 | image_url = data['data']['Media']['coverImage']['large'] |
| @@ -269,11 +285,15 @@ def get_user_data(access_token, user_id): | ||
| 269 | 285 | """ % user_id |
| 270 | 286 | |
| 271 | 287 | # 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) | |
| 277 | 297 | |
| 278 | 298 | |
| 279 | 299 | # Print the response |
| @@ -334,9 +354,12 @@ def update_anime_progress(token: str, media_id: int, progress: int): | ||
| 334 | 354 | "Content-Type": "application/json", |
| 335 | 355 | "Accept": "application/json" |
| 336 | 356 | } |
| 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 | ||
| 340 | 363 | if response.status_code == 200: |
| 341 | 364 | data = response.json() |
| 342 | 365 | updated_progress = data['data']['SaveMediaListEntry']['progress'] |
| @@ -473,7 +496,7 @@ def select_anime(anime_list): | ||
| 473 | 496 | curses.endwin() |
| 474 | 497 | print("Have a great day!") |
| 475 | 498 | os._exit(0) |
| 476 | ||
| 499 | ||
| 477 | 500 | # Handle key inputs |
| 478 | 501 | if key in [curses.KEY_BACKSPACE, 127, 8]: |
| 479 | 502 | current_input = current_input[:-1] |