Skip to content

Commit

Permalink
add function to convert from al to mal id
Browse files Browse the repository at this point in the history
  • Loading branch information
prochy-exe committed May 11, 2024
1 parent 92db927 commit 2788053
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion alfetcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .al_fetcher import check_status_in_cache, get_userdata, reset_user_cache, clear_cache, get_latest_anime_entry_for_user, get_all_anime_for_user, get_anime_entry_for_user, get_anime_info, get_id
from .al_fetcher import check_status_in_cache, get_userdata, reset_user_cache, clear_cache, get_latest_anime_entry_for_user, get_all_anime_for_user, get_anime_entry_for_user, get_anime_info, get_id, al_to_mal_id
from .utils import utils_read_json, utils_save_json
from .al_config_utils import config_setup
18 changes: 17 additions & 1 deletion alfetcher/al_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,20 @@ def get_userdata(anilist_token=None):
# Extract the username from the response data
username = data['Viewer']['name']
profile_pic = data['Viewer']['avatar']['large']
return [username, profile_pic]
return [username, profile_pic]

def al_to_mal_id(al_id):
query = """
query ($mediaId: Int) {
Media(id: $mediaId, type: ANIME) {
idMal
}
}
"""
variables = {'mediaId': al_id}
data = make_graphql_request(query, variables)

if data:
return int(data['Media']['idMal'])
return None

0 comments on commit 2788053

Please sign in to comment.