diff --git a/fastanime/__init__.py b/fastanime/__init__.py index d9c4a75..ccecac0 100644 --- a/fastanime/__init__.py +++ b/fastanime/__init__.py @@ -39,6 +39,21 @@ def FastAnime(): handlers=[RichHandler()], # Use RichHandler to format the logs ) sys.argv.remove("--log") + if "--log-file" in sys.argv: + # Configure logging + from rich.logging import RichHandler + + from .constants import NOTIFIER_LOG_FILE_PATH + + logging.getLogger(__name__) + logging.basicConfig( + level=logging.DEBUG, # Set the logging level to DEBUG + format="%(asctime)s%(levelname)s: %(message)s", # Use a simple message format + datefmt="[%d/%m/%Y@%H:%M:%S]", # Use a custom date format + filename=NOTIFIER_LOG_FILE_PATH, + filemode="a", # Use RichHandler to format the logs + ) + sys.argv.remove("--log-file") from .cli import run_cli diff --git a/fastanime/constants.py b/fastanime/constants.py index a1661b1..1c89933 100644 --- a/fastanime/constants.py +++ b/fastanime/constants.py @@ -21,6 +21,7 @@ if not APP_DATA_DIR: USER_DATA_PATH = os.path.join(APP_DATA_DIR, "user_data.json") USER_CONFIG_PATH = os.path.join(APP_DATA_DIR, "config.ini") +NOTIFIER_LOG_FILE_PATH = os.path.join(APP_DATA_DIR, "notifier.log") # cache dir APP_CACHE_DIR = dirs.user_cache_dir diff --git a/fastanime/libs/anilist/api.py b/fastanime/libs/anilist/api.py index e9528b3..49a7d88 100644 --- a/fastanime/libs/anilist/api.py +++ b/fastanime/libs/anilist/api.py @@ -13,12 +13,14 @@ from .queries_graphql import ( anime_query, anime_relations_query, get_logged_in_user_query, + mark_as_read_mutation, media_list_mutation, media_list_query, most_favourite_query, most_popular_query, most_recently_updated_query, most_scored_query, + notification_query, recommended_query, search_query, trending_query, @@ -46,6 +48,12 @@ class AniListApi: self.user_id = user_info["id"] # pyright:ignore return user_info + def get_notification(self): + return self._make_authenticated_request(notification_query) + + def reset_notification_count(self): + return self._make_authenticated_request(mark_as_read_mutation) + def update_login_info(self, user: AnilistUser, token: str): self.token = token self.headers = {"Authorization": f"Bearer {self.token}"} diff --git a/fastanime/libs/anilist/queries_graphql.py b/fastanime/libs/anilist/queries_graphql.py index b30bb4a..172472f 100644 --- a/fastanime/libs/anilist/queries_graphql.py +++ b/fastanime/libs/anilist/queries_graphql.py @@ -3,6 +3,41 @@ This module contains all the preset queries for the sake of neatness and convini Mostly for internal usage """ +mark_as_read_mutation = """ +mutation{ + UpdateUser{ + unreadNotificationCount + } +} +""" +notification_query = """ +query{ + Page { + pageInfo { + total + } + notifications(resetNotificationCount:true,type:AIRING) { + ... on AiringNotification { + id + type + episode + contexts + createdAt + media { + id + title { + romaji + english + } + } + } + } + } +} + +""" + + get_logged_in_user_query = """ query{ Viewer{ @@ -46,8 +81,8 @@ media_list_query = """ query ($userId: Int, $status: MediaListStatus) { Page { pageInfo { - currentPage - total + currentPage + total } mediaList(userId: $userId, status: $status) { mediaId