import logging


def get_broadcasts(resp):
    """Parses an NHL schedule response to get broadcast information.

    Args:
        resp: JSON response from NHL Schedule API call.

    Returns:
        broadcasts: Dictionary of home & away broadcasts.
    """
    broadcasts = {}

    # Set defaults in case one team doesn't have a broadcast yet
    # broadcasts["home"] = "TBD"
    # broadcasts["away"] = "TBD"

    try:
        resp_broadcasts = resp["broadcasts"]
        for broadcast in resp_broadcasts:
            broadcast_team = broadcast["type"]
            if broadcast_team == "national":
                broadcasts["away"] = broadcast["name"]
                broadcasts["home"] = broadcast["name"]
                break
            else:
                broadcast_channel = broadcast["name"]
                broadcasts[broadcast_team] = broadcast_channel
    except KeyError:
        logging.warning("Broadcasts not available - setting them to TBD.")
        broadcasts["home"] = "TBD"
        broadcasts["away"] = "TBD"

    return broadcasts