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)
def second_power_players(bot, update, args): if args: user = determine_user(args[0]) bot.send_message(update.message.chat_id, get_second_power_player_for_user(user)) else: bot.send_message(update.message.chat_id, simple_table(get_second_power_players()))
def stealths_left(bot, update, args): if args: user = determine_user(args[0]) bot.send_message(update.message.chat_id, get_stealth_left_for_user(user)) else: bot.send_message(update.message.chat_id, simple_table(get_stealths_left()))
def sub_strike_rate(bot, update, args): if args: user = determine_user(args[0]) bot.send_message(update.message.chat_id, get_sub_strike_rate_for_user(user)) else: bot.send_message(update.message.chat_id, simple_table(get_sub_strike_rates()))
def top_picks(bot, update, args): rankings = [] if (args): team = determine_team(args[0]) rankings = get_top_picks(team) else: rankings = get_top_picks() rankings_table = [] for rank in rankings: row = [rank[1], rank[5], rank[2]] rankings_table.append(row) bot.send_message(update.message.chat_id, simple_table(rankings_table))
def subs_left(bot, update, args): if args: user = determine_user(args[0]) bot.send_message(update.message.chat_id, get_subs_left_for_user(user)) else: matches_left = 7949 - int(get_match_id()) + 1 projected_subs = int(75 / 55 * matches_left) resp = "Matches left: {} \n".format(matches_left) resp += "Projected Subs: {}\n".format(projected_subs) subs_left = get_subs_left() resp += simple_table(subs_left) bot.send_message(update.message.chat_id, resp)
def live_fantasy_scores(bot, update, args): resp = get_score_card() resp += "\n" if args: user = determine_user(args[0]) live_data = get_live_data_for_user(user) user_players = get_squad_details(user)['players'] player_points = [] for player in live_data['playerPoints']: if player['playerId'] in user_players: points = get_points_from_live_player_points(player) if not points: continue player_points.append( (get_player(player['playerId']).name, points)) player_points = sorted(player_points, key=lambda x: int(x[1]), reverse=True) resp += "Live Points: {} \n".format( get_total_points_from_live_data(live_data)) resp += simple_table(player_points) bot.send_message(update.message.chat_id, resp) else: live_scores = [] for user in USER_IDS: live_data = get_live_data_for_user(user) score = get_total_points_from_live_data(live_data) live_scores.append((get_league_team_name_for_user(user), score)) live_scores.sort(key=lambda x: int(x[1]), reverse=True) resp += simple_table(live_scores) bot.send_message(update.message.chat_id, resp)
def picked_players(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: /pickedplayers <team1> <team2> ...") return args = list(map(determine_team, args)) ipl_players = get_ipl_player_to_users_mapping(args) data = sorted(ipl_players.items(), key=lambda x: len(x[1]), reverse=True) data = list(map(lambda x: (x[0], ", ".join(x[1])), data)) bot.send_message(update.message.chat_id, simple_table(data))
def mult_left(bot, update, args): mult_left = [] if args: user = determine_user(args[0]) squad_details = get_squad_details(user) bot.send_message(update.message.chat_id, _get_mult_left(squad_details)) return for user_id in USER_IDS: squad_details = get_squad_details(user_id) mult_left.append((get_league_team_name_for_user(user_id), _get_mult_left(squad_details))) mult_left.sort(key=lambda x: int(x[1]), reverse=True) resp = "2X left: \n" resp += simple_table(mult_left) bot.send_message(update.message.chat_id, resp)
def points_of(bot, update, args): live_points = get_live_points() if len(args) >= 1: query_player = args[0] player = determine_player(query_player) for live_point in live_points: if int(live_point[0]) == int(player.id): bot.send_message( update.message.chat_id, "Player - {}: {}".format(player.name, live_point[1])) return bot.send_message(update.message.chat_id, "Points not found for {}".format(player.name)) return live_points = map(lambda x: (get_player(x[0]).name, x[1]), live_points) bot.send_message(update.message.chat_id, simple_table(live_points))
def cumulative_scores(bot, update, args): bot.send_message(update.message.chat_id, simple_table(get_live_total_scores(args)))