diff options
Diffstat (limited to 'src/due/media.py')
| -rw-r--r-- | src/due/media.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/due/media.py b/src/due/media.py index 8c86855..67d9e01 100644 --- a/src/due/media.py +++ b/src/due/media.py @@ -2,17 +2,20 @@ import requests def user_id(anilist): - return int( - requests.post( - "https://graphql.anilist.co", - json={"query": "{ Viewer { id } }"}, - headers={ - "Authorization": anilist["token_type"] + " " + anilist["access_token"], - "Content-Type": "application/json", - "Accept": "application/json", - }, - ).json()["data"]["Viewer"]["id"] - ) + viewer = requests.post( + "https://graphql.anilist.co", + json={"query": "{ Viewer { id } }"}, + headers={ + "Authorization": anilist["token_type"] + " " + anilist["access_token"], + "Content-Type": "application/json", + "Accept": "application/json", + }, + ).json()["data"]["Viewer"] + + if viewer is None: + return -1 + + return int(viewer["id"]) def last_activity(id): |