from bs4 import BeautifulSoup
from typing import Dict
from typing import List


def get_creator(soup: BeautifulSoup, persons: Dict[str, str]) -> str:
    """Get creator(s).

    Args:
        soup (bs4.BeautifulSoup): BeautifulSoup object
        persons (Dict[str, str]): look-up table for person names by ID

    Returns:
        str: creator name(s)
    """
    hands = soup.handDesc

    if hands:
        try:
            creators = hands.find_all('name', {'type': 'person'})

            if not creators:
                pretty_creators = "Scribe(s) unknown"
            else:
                names: List[str] = []
                for creator in creators:
                    key = creator.get('key')
                    if key:
                        name = persons.get(key)
                        if name:
                            names.append(name)
                pretty_creators = '; '.join(names)
        except:
            # LATER: find out why, if that happens
            pretty_creators = "Scribe(s) unknown"
    else:
        # LATER: find out why, if that happens
        pretty_creators = "Scribe(s) unknown"

    return pretty_creators