from pathlib import Path


def wikipedia_language(filepath):
    """Parse the filename to find the language code of a scraped wikipedia file

    The function assumes a path such as:

        /some/folder/xyz.wikipedia.org/some/file

    This function returns the language code xyz (2 or 3 letters).

    Raise `ValueError` if filepath has no wikipedia hostname component.
    """
    for part in Path(filepath).parts:
        if part.endswith(".wikipedia.org"):
            return part.split(".")[0]
    raise ValueError(f"{filepath} has no Wikipedia language information")