Exemple #1
0
def footy_fixtures_today(room: str, username: str) -> Optional[List[int]]:
    """
    Gets fixture IDs of fixtures being played today.

    :param str room: Chatango room which triggered the command.
    :param str username: Chatango user who triggered the command.

    :returns: Optional[List[int]]
    """
    try:
        today = datetime.now()
        display_date, tz = get_preferred_time_format(today, room, username)
        params = {"date": display_date}
        params.update(get_preferred_timezone(room, username))
        res = requests.get(FOOTY_FIXTURES_ENDPOINT,
                           headers=FOOTY_HTTP_HEADERS,
                           params=params)
        fixtures = res.json().get("response")
        if bool(fixtures):
            return [
                fixture["fixture"]["id"] for fixture in fixtures
                if fixture["league"]["id"] in FOOTY_LEAGUES.values()
            ]
    except HTTPError as e:
        LOGGER.error(
            f"HTTPError while fetching today's footy fixtures: {e.response.content}"
        )
    except KeyError as e:
        LOGGER.error(f"KeyError while fetching today's footy fixtures: {e}")
    except Exception as e:
        LOGGER.error(
            f"Unexpected error when fetching today's footy fixtures: {e}")
Exemple #2
0
def footy_live_fixtures(room: str, username: str, subs=False) -> str:
    """
    Fetch live fixtures for EPL, LIGA, BUND, FA, UCL, EUROPA, etc.

    :param str room: Chatango room in which command was triggered.
    :param str username: Name of user who triggered the command.
    :param bool subs: Whether to include substitutions in match summaries.

    :returns: str
    """
    live_fixtures = "\n\n\n\n"
    i = 0
    for league_name, league_id in FOOTY_LEAGUES.items():
        live_league_fixtures = footy_live_fixtures_per_league(league_id,
                                                              league_name,
                                                              room,
                                                              username,
                                                              subs=subs)
        if live_league_fixtures is not None and i < 6:
            i += 1
            live_fixtures += live_league_fixtures + "\n"
    if live_fixtures == "\n\n\n\n":
        return emojize(":warning: No live fixtures :( :warning:",
                       use_aliases=True)
    return live_fixtures
Exemple #3
0
def footy_all_upcoming_fixtures(room: str, username: str) -> str:
    """
    Fetch upcoming fixtures within 1 week for ALL leagues.

    :param str room: Chatango room in which command was triggered.
    :param str username: Name of user who triggered the command.

    :returns: str
    """
    upcoming_fixtures = "\n\n\n\n"
    for league_name, league_id in FOOTY_LEAGUES.items():
        league_fixtures = footy_upcoming_fixtures_per_league(league_name, league_id, room, username)
        if league_fixtures is not None:
            upcoming_fixtures += emojize(f"<b>{league_name}:</b>\n", use_aliases=True)
            upcoming_fixtures += league_fixtures + "\n"
    if upcoming_fixtures != "\n\n\n\n":
        return upcoming_fixtures
    return emojize(":warning: Couldn't find any upcoming fixtures :( :warning:", use_aliases=True)
Exemple #4
0
def today_upcoming_fixtures(room: str, username: str) -> str:
    """
    Fetch fixtures scheduled to occur today.

    :param str room: Chatango room in which command was triggered.
    :param str username: Name of user who triggered the command.

    :returns: str
    """
    upcoming_fixtures = "\n\n\n\n"
    i = 0
    for league_name, league_id in FOOTY_LEAGUES.items():
        league_fixtures = today_upcoming_fixtures_per_league(
            league_name, league_id, room, username)
        if league_fixtures is not None and i < 5:
            i += 1
            upcoming_fixtures += league_fixtures + "\n"
    if upcoming_fixtures != "\n\n\n\n":
        return upcoming_fixtures
    return emojize(
        f":soccer_ball: :cross_mark: sry @{username} no fixtures today :( :cross_mark: :soccer_ball:",
        use_aliases=True,
    )