Exemplo n.º 1
0
def schedule(bot, update, args):
    all_matches = get_matches()

    pacific_tz = pytz.timezone('US/Pacific')
    now = arrow.now().astimezone(pacific_tz)

    resp = "Next matches: \n"
    next_matches = [
        match for match in all_matches
        if arrow.get(match.starttime).astimezone(pacific_tz) > now
    ]

    if args:
        if _is_int(args[0]):
            n = int(args[0])
            resp = "Next {} matches: \n".format(n)
            next_matches = next_matches[:n]
        else:
            team = determine_team(args[0])
            resp = "Next {} matches: \n".format(team)
            next_matches = [
                match for match in next_matches if team in match.teams
            ]

    matches_table = []
    for match in next_matches:
        row = [
            str(arrow.get(match.starttime).astimezone(pacific_tz).date())[5:]
        ]
        row.extend(list(map(team_short_name, match.teams)))
        matches_table.append(row)

    resp += "Today: {} \n".format(str(now.date())[5:])
    resp += simple_table(matches_table)
    bot.send_message(update.message.chat_id, resp)
Exemplo n.º 2
0
def next_opportunities(bot, update, args):
    if not args:
        bot.send_message(update.message.chat_id, "Usage: /nextin bravo")
        return

    player = determine_player(args[0])
    all_matches = get_matches()

    pacific_tz = pytz.timezone('US/Pacific')
    now = arrow.now().astimezone(pacific_tz)

    next_opportunity = 0
    opps = []

    for match in all_matches:
        starttime = arrow.get(match.starttime).astimezone(pacific_tz)
        if now > starttime:
            continue

        next_opportunity += 1
        if player.team in match.teams:
            # This is tricky but basically finds the complement in the list
            opposing_team = match.teams[int(
                not match.teams.index(player.team))]

            opps.append((str(starttime.date()), team_short_name(opposing_team),
                         next_opportunity))

    resp = "Player: {} \n".format(player.name)
    resp += tabulate(opps, headers=('date', 'vs', 'matches to go'))
    bot.send_message(update.message.chat_id, resp)
Exemplo n.º 3
0
def test_get_matches():
    matches = get_matches()
    assert len(matches) == 56

    match = matches[0]
    starttime = arrow.get(match.starttime)
    now = arrow.now()

    assert (now.date() - starttime.date()).days >= 20
Exemplo n.º 4
0
def players_of(bot, update, args):
    # bot.send_message(update.message.chat_id, "Stealth for life!")
    # return
    if not args:
        bot.send_message(update.message.chat_id, "Usage: /playersof badri mi")
        return

    user = determine_user(args[0])
    squad_details = get_squad_details(user)
    players = [get_player(p) for p in squad_details['players']]

    if len(args) > 1:
        teams = list(map(determine_team, args[1:]))
        players = [p for p in players if p['team'] in teams]

    if not players:
        bot.send_message(update.message.chat_id, "No players")
        return

    players_table = []

    pacific_tz = pytz.timezone('US/Pacific')
    now = arrow.now().astimezone(pacific_tz)
    matches = get_matches()
    for player in players:
        next_opportunity = 0
        for match in matches:
            starttime = arrow.get(match.starttime).astimezone(pacific_tz)
            if now > starttime:
                continue
            next_opportunity += 1
            if player.team in match.teams:
                break
        players_table.append(
            (_get_player_name(player, squad_details), next_opportunity))

    message = tabulate.tabulate(players_table,
                                headers=['Player', 'nextopportunityin'])
    resp = "Total Players: {} \n".format(len(players_table))
    resp += message

    bot.send_message(update.message.chat_id, resp)
Exemplo n.º 5
0
def test_teams_and_players_teams_match():
    players = get_players()
    players_teams = [player.team for player in players.values()]
    matches_teams = [team for match in get_matches() for team in match.teams]
    assert (set(players_teams) - set(matches_teams)) == set()