<reponame>Nearata/myanimelist-rest-api<gh_stars>1-10
from re import match
from typing import Optional

from bs4 import BeautifulSoup


class Clubs:
    def __init__(self, soup: BeautifulSoup, base_url: str) -> None:
        self.soup = soup
        self.base_url = base_url

    def __call__(self) -> dict:
        return {
            "data": [
                {
                    "name": i.select_one("a").get_text(strip=True),
                    "url": f"{self.base_url}{i.select_one('a').get('href')}",
                    "members": self.__members(i.select_one("small").get_text()),
                }
                for i in self.soup.find_all("div", {"class": "borderClass"})
            ]
        }

    def __members(self, string: str) -> Optional[int]:
        regex = match(r"\d+", string)
        return int(regex.group()) if regex else None

from re import match
from typing import Optional

from bs4 import BeautifulSoup


class Clubs:
    def __init__(self, soup: BeautifulSoup, base_url: str) -> None:
        self.soup = soup
        self.base_url = base_url

    def __call__(self) -> dict:
        return {
            "data": [
                {
                    "name": i.select_one("a").get_text(strip=True),
                    "url": f"{self.base_url}{i.select_one('a').get('href')}",
                    "members": self.__members(i.select_one("small").get_text()),
                }
                for i in self.soup.find_all("div", {"class": "borderClass"})
            ]
        }

    def __members(self, string: str) -> Optional[int]:
        regex = match(r"\d+", string)
        return int(regex.group()) if regex else None