feat(anilist): add notifier command

This commit is contained in:
Benex254
2024-08-05 09:47:04 +03:00
parent 7717ceeb54
commit 23012ad645
4 changed files with 61 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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}"}

View File

@@ -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