diff --git a/alfetcher/__init__.py b/alfetcher/__init__.py index 8a2aa9f..79acff9 100644 --- a/alfetcher/__init__.py +++ b/alfetcher/__init__.py @@ -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 \ No newline at end of file diff --git a/alfetcher/al_fetcher.py b/alfetcher/al_fetcher.py index bc283cf..048ffb2 100644 --- a/alfetcher/al_fetcher.py +++ b/alfetcher/al_fetcher.py @@ -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] \ No newline at end of file + 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 +