Moved AnyDict to seperate file
This commit is contained in:
parent
ec2471a932
commit
7b86003d9f
@ -3,6 +3,7 @@ import typing
|
||||
from dotenv import load_dotenv
|
||||
from al_arr_sync.anilist import AniListClient
|
||||
from al_arr_sync.sonarr import SonarrClient
|
||||
from al_arr_sync.types import AnyDict
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@ -14,7 +15,7 @@ def main() -> int:
|
||||
username = os.environ["ANILIST_USERNAME"]
|
||||
media = al.currently_watching(username)
|
||||
|
||||
series: typing.List[typing.Any] = []
|
||||
series: typing.List[AnyDict] = []
|
||||
for entry in media:
|
||||
media_format = entry["media"]["format"]
|
||||
if media_format == "TV":
|
||||
|
@ -1,8 +1,6 @@
|
||||
import typing
|
||||
from requests import Session
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
AnyDict = typing.Dict[typing.Any, typing.Any]
|
||||
from al_arr_sync.types import AnyDict
|
||||
|
||||
|
||||
USER_WATCHING_QUERY = """
|
||||
@ -28,12 +26,12 @@ class AniListClient:
|
||||
self.graphql_api_url = "https://graphql.anilist.co/"
|
||||
self.http_session = Session()
|
||||
|
||||
def currently_watching(self, username: str) -> typing.List['AnyDict']:
|
||||
def currently_watching(self, username: str) -> typing.List[AnyDict]:
|
||||
resp = self.http_session.post(
|
||||
self.graphql_api_url,
|
||||
json={"query": USER_WATCHING_QUERY, "variables": {"userName": username}},
|
||||
)
|
||||
resp_data: 'AnyDict' = resp.json()
|
||||
resp_data: AnyDict = resp.json()
|
||||
if errors := resp_data.get("errors"):
|
||||
raise Exception(errors)
|
||||
|
||||
|
@ -3,9 +3,8 @@ from requests import Session
|
||||
from requests import PreparedRequest
|
||||
import os
|
||||
from urllib.parse import urljoin
|
||||
from al_arr_sync.types import AnyDict
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
AnyDict = typing.Dict[typing.Any, typing.Any]
|
||||
|
||||
class SonarrClient:
|
||||
def __init__(self, sonarr_url: str, api_key: str) -> None:
|
||||
@ -24,8 +23,8 @@ class SonarrClient:
|
||||
self,
|
||||
endpoint: str,
|
||||
method: str = "GET",
|
||||
params: 'AnyDict' = {},
|
||||
json: typing.Optional['AnyDict'] = None,
|
||||
params: AnyDict = {},
|
||||
json: typing.Optional[AnyDict] = None,
|
||||
) -> PreparedRequest:
|
||||
url = urljoin(self.sonarr_url, endpoint)
|
||||
headers = {"X-Api-Key": self.api_key}
|
||||
@ -34,14 +33,14 @@ class SonarrClient:
|
||||
req.prepare(method=method, url=url, headers=headers, params=params, json=json)
|
||||
return req
|
||||
|
||||
def lookup_series(self, title: str) -> typing.List['AnyDict']:
|
||||
def lookup_series(self, title: str) -> typing.List[AnyDict]:
|
||||
req = self._prepare_request("/api/v3/series/lookup", params={"term": title})
|
||||
resp = self.http_session.send(req)
|
||||
return resp.json()
|
||||
|
||||
def add_series(self, *series: 'AnyDict'):
|
||||
def add_series(self, *series: AnyDict):
|
||||
for show in series:
|
||||
payload: 'AnyDict' = show.copy()
|
||||
payload: AnyDict = show.copy()
|
||||
payload.update(
|
||||
{
|
||||
"addOptions": {
|
||||
|
3
al_arr_sync/types.py
Normal file
3
al_arr_sync/types.py
Normal file
@ -0,0 +1,3 @@
|
||||
import typing
|
||||
|
||||
AnyDict = typing.Dict[typing.Any, typing.Any]
|
Loading…
x
Reference in New Issue
Block a user