1
0
personal-data/personal_data/fetchers/myanimelist.py
Jon Michael Aanes a27ffe6ddb
All checks were successful
Run Python tests (through Pytest) / Test (push) Successful in 38s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 33s
Move most of the client code into dedicated MyAnimeList client
2025-05-06 00:47:30 +02:00

38 lines
1.1 KiB
Python

import dataclasses
import json
import logging
import re
import urllib.parse
from collections.abc import Iterator
import bs4
from clients.myanimelist import MyAnimeListClient, MyAnimeListAnime, MyAnimeListSong
from clients import init_client
from personal_data.data import DeduplicateMode, Scraper
from .. import secrets
logger = logging.getLogger(__name__)
def client(session):
return init_client(MyAnimeListClient, session, secrets.secrets, throws=True)
@dataclasses.dataclass(frozen=True)
class MyAnimeList(Scraper):
dataset_name = 'myanimelist_anime'
deduplicate_mode = DeduplicateMode.BY_FIRST_COLUMN
def scrape(self) -> Iterator[MyAnimeListAnime]:
yield from client(self.session).get_my_anime_list()
@dataclasses.dataclass(frozen=True)
class MyAnimeListSongs(Scraper):
dataset_name = 'myanimelist_songs'
deduplicate_mode = DeduplicateMode.BY_FIRST_COLUMN
def scrape(self) -> Iterator[MyAnimeListSong]:
my_client = client(self.session)
for anime in my_client.get_my_anime_list():
yield from my_client.get_songs_for_anime(anime)