Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Add followings.py query
Browse files Browse the repository at this point in the history
  • Loading branch information
RLAlpha49 committed May 20, 2024
1 parent 39d3dae commit 8293c7f
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 104 deletions.
48 changes: 48 additions & 0 deletions AniLinkPy/apis/anilist/query/page/followings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import Dict, Union

from AniLinkPy.apis.anilist.schemas.query.user_schema import USERSCHEMA
from AniLinkPy.base.RequestHandler import send_request


class FollowingsQuery:
"""
This class represents a Followings_schema Query in the AniLink API.
Attributes:
base_url (str): The base URL for the AniLink API.
auth_token (str): The authentication token.
"""

def __init__(self, auth_token: Union[str, None]) -> None:
"""
The constructor for the FollowingsQuery class.
Args:
auth_token (str): The authentication token.
"""
self.base_url = "https://graphql.anilist.co"
self.auth_token = auth_token

def followings(self, variables: Union[Dict[str, Union[str, int, bool]]]) -> dict:
"""
This method is used to send a followings Query.
Args:
variables (dict): The variables for the Query.
Raises:
ValueError: If no variables are provided.
Returns:
dict: The response from the airingSchedules Query.
"""

query = f"""
query ($page: Int, $perPage: Int, $userId: Int!, $sort: [UserSort], $asHtml: Boolean,
$animeStatLimit: Int, $mangaStatLimit: Int, $animeStatSort: [UserStatisticsSort], $mangaStatSort: [
UserStatisticsSort]) {{ Page (page: $page, perPage: $perPage) {{ pageInfo {{ total perPage currentPage
lastPage hasNextPage }} following (userId: $userId, sort: $sort) {{ {USERSCHEMA} }}}}}}
"""

data = {"query": query, "variables": variables}
return send_request(self.base_url, "POST", data, self.auth_token)
18 changes: 18 additions & 0 deletions AniLinkPy/apis/anilist/query/page/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from AniLinkPy.apis.anilist.query.page.airing_schedules import AiringSchedulesQuery
from AniLinkPy.apis.anilist.query.page.characters import CharactersQuery
from AniLinkPy.apis.anilist.query.page.followers import FollowersQuery
from AniLinkPy.apis.anilist.query.page.followings import FollowingsQuery


class Page:
Expand All @@ -28,6 +29,7 @@ def __init__(self, auth_token: Union[str, None]) -> None:
self.airing_schedules_query = AiringSchedulesQuery(auth_token)
self.characters_query = CharactersQuery(auth_token)
self.followers_query = FollowersQuery(auth_token)
self.followings_query = FollowingsQuery(auth_token)

def activities(
self, variables: Union[Dict[str, Union[str, int, bool]], None] = None
Expand Down Expand Up @@ -108,3 +110,19 @@ def followers(
if variables is None:
variables = {}
return self.followers_query.followers(variables)

def followings(
self, variables: Union[Dict[str, Union[str, int, bool]], None] = None
) -> dict:
"""
This method is used to get followings.
Args:
variables (dict): The variables for the Query.
Returns:
dict: The response from the followings Query.
"""
if variables is None:
variables = {}
return self.followings_query.followings(variables)
Loading

0 comments on commit 8293c7f

Please sign in to comment.