from warnings import warn


def extract_table_parts(page):
    """Extract head and body from the calendar table on the given page."""
    # Find the calendar table
    tables = page.select("table")
    if len(tables) == 0:
        raise RuntimeError("There are no tables on this page.")
    if len(tables) > 1:
        warn("There are more tables on the page.  I will use the first one.")
    cal_table = tables[0] # It seems to be the only table on the page
    headlist = cal_table.find_all("thead")
    if len(headlist) == 0:
        raise RuntimeError("The table I found does not seem to have a head.")
    if len(headlist) > 1:
        warn("This table has more than one head.")
    head = headlist[0]
    bodylist = cal_table.find_all("tbody")
    if len(bodylist) == 0:
        raise RuntimeError("The table I found does not seem to have a body.")
    if len(bodylist) > 1:
        warn("This table has more than one body.")
    body = bodylist[0]

    return head, body