Szerkesztő:BinBot/huwiki/biography.py

Expanation / Magyarázat

"""Handle biographies (main namespace articles about people) in huwiki."""
#
# (C) Bináris, 2023
#
# Distributed under the terms of the MIT license.

from typing import Union
import pywikibot
from .article import Article
from .category import CatProperties

site = pywikibot.Site()

class Biography(Article):
    """A page about a person in main namespace.

    May be instantiated with either Page, Article or title.
    """

    def __init__(self,
                 title: Union[pywikibot.Page, Article, str],
                 force_check: bool = True
                 ) -> None:
        """Initializer.

        :param force_check: if True, will raise a TypeError unless
        is_person() = True. This check is slow. If you decide to skip
        it by explicitely setting the argument to False, it is your
        responsibility to instantiate only biographies.
        :raises TypeError: see above
        """
        if isinstance(title, (pywikibot.Page, Article)):
            title = title.title()
        super(Biography, self).__init__(title)
        if force_check and not self.is_person():
            raise TypeError(f'Page must be biography of a person: {title}.')

    # ---------------------------------------------
    # Functions dealing with categories of the page
    # ---------------------------------------------

    def has__cityzencat(self) -> bool:
        """Does it have a "city" category like 'Budapestiek'?

        Currently not safe. May produce false negatives. Slow.
        """
        for cat in self.categories():
            if CatProperties(cat).is_cityzencat():
                return True
        return False