diff --git a/alfetcher/__init__.py b/alfetcher/__init__.py index 79acff9..0eeee60 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, al_to_mal_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, update_entry 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 048ffb2..2de397b 100644 --- a/alfetcher/al_fetcher.py +++ b/alfetcher/al_fetcher.py @@ -635,3 +635,32 @@ def al_to_mal_id(al_id): return int(data['Media']['idMal']) return None +def update_entry(anime_id, progress, anilist_token=None): + progress = int(progress) + total_eps = get_anime_info(anime_id, anilist_token=anilist_token)[anime_id]['total_eps'] + query = """ + mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus) { + SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status) { + id + } + } + """ + variables = {} + variables['mediaId'] = anime_id + variables['progress'] = progress + if progress == total_eps: + variables['status'] = 'COMPLETED' + elif progress == 0: + variables['status'] = 'PLANNING' + query = """ + mutation ($mediaId: Int, $status: MediaListStatus) { + SaveMediaListEntry(mediaId: $mediaId, status: $status) { + id + } + } + """ + del variables['progress'] + else: + variables['status'] = 'CURRENT' + make_graphql_request(query, variables, anilist_token) + print('Updating progress successful') \ No newline at end of file