mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-29 06:03:29 -08:00
feat(anilist): add notifier command
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user