aboutsummaryrefslogtreecommitdiff
path: root/authentication/utils.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-08-26 20:34:24 -0400
committerBobby <[email protected]>2024-08-26 20:34:24 -0400
commit187867f8740cd8cca55fbc196d7a07a35d49d274 (patch)
tree8de4178dad31e55b40140dc828e5c43c03a120e0 /authentication/utils.py
parent54e21f54cf5b36406ffcea82ee49be175b5a2fbe (diff)
downloadyugen-187867f8740cd8cca55fbc196d7a07a35d49d274.tar.xz
yugen-187867f8740cd8cca55fbc196d7a07a35d49d274.zip
Update MAL from site
Diffstat (limited to 'authentication/utils.py')
-rw-r--r--authentication/utils.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/authentication/utils.py b/authentication/utils.py
index 0283f32..8c585c7 100644
--- a/authentication/utils.py
+++ b/authentication/utils.py
@@ -75,11 +75,15 @@ def exchange_code(code):
)
return response.json()
-def get_user_mal_list(access_token, limit=10, offset=0):
+def get_user_mal_list(access_token, limit=10, offset=0, filter=""):
if not access_token or access_token == "":
return [], None, None
base_url = f"https://api.myanimelist.net/v2/users/@me/animelist?limit={limit}&offset={offset}&fields=my_list_status,alternative_titles,anime&sort=list_updated_at"
+
+ if filter:
+ base_url += f"&status={filter}"
+
headers = {"Authorization": f"Bearer {access_token}"}
response = requests.get(base_url, headers=headers)
@@ -107,7 +111,21 @@ def get_user_mal_list(access_token, limit=10, offset=0):
return user_anime_list, page_previous, page_next
-
+def get_single_anime_mal(access_token, mal_id):
+ if not access_token or access_token == "":
+ return None
+
+ base_url = f"https://api.myanimelist.net/v2/anime/{mal_id}?fields=alternative_titles,average_episode_duration,broadcast,created_at,end_date,genres,id,main_picture,media_type,nsfw,num_episodes,num_favorites,num_list_users,num_scoring_users,popularity,rank,start_date,start_season,status,synopsis,source,studios,title,updated_at,my_list_status,background,related_anime,rating,mean"
+
+ headers = {"Authorization": f"Bearer {access_token}"}
+ response = requests.get(base_url, headers=headers)
+
+ if response.status_code == 200:
+ data = response.json()
+ return data
+ else:
+ print(response.json(), "MAL API Error")
+ return None
def get_discord_user(access_token, token_type):
guilds = requests.get(