def toss(bot, update): scoring_info = get_scoring_info() toss_info = jmespath.search('matchInfo.additionalInfo."toss.elected"', scoring_info) if not toss_info: bot.send_message(update.message.chat_id, "No toss and team info found yet.") return resp = "Toss Info: {} \n".format(toss_info) teams = jmespath.search('matchInfo.teams', scoring_info) if teams: for team in teams: if team['players']: resp += "Team: {} \n".format(team['team']['abbreviation']) resp += ",".join([ get_player(player['id']).name for player in team['players'] ]) resp += "\n" else: resp += "No squad info found for this team yet. Check back shortly. \n" else: resp += "No squad info found yet. Check back shortly." bot.send_message(update.message.chat_id, resp)
def main(event, context): squad_history = defaultdict(list) current_match_id = get_match_id() for user in USER_IDS: points_history = get_points_history_for_user(user)['pointsHistory'] for match_id in range(7894, current_match_id): print("Processing {} {}".format(user, match_id)) match = get_match(match_id) try: squad_details = get_squad_details(user, match_id) except KeyError: print("Unable to get details for {} {}".format(user, match_id)) continue players = [get_player(p) for p in squad_details['players']] squad_details['players'] = [p.name for p in players] squad_details['powerPlayer'] = get_player(squad_details['powerPlayer']).name squad_details['secondPowerPlayer'] = get_player(squad_details['secondPowerPlayer']).name squad_details['matchDescription'] = match.description squad_details['teams'] = match.teams squad_details['numPlayersPlaying'] = len([p for p in players if p.team in match.teams]) squad_details['pointsScored'] = get_points_of_match(points_history, match_id) del squad_details['transfersRemaining'] del squad_details['stealthList'] del squad_details['doublePointsList'] del squad_details['freeTransfer'] squad_history[get_league_team_name_for_user(user)].append(squad_details) print("Uploading data to s3") s3_client = boto3.client('s3') s3_client.put_object(Bucket=os.environ.get('S3_STORAGE_BUCKET', 'com.baebot.dev.storage'), Key="teams_squad_history.json", Body=json.dumps(squad_history)) return {"statusCode": 200}
def get_all_players_rank_data(): #return get_squad_details('*****@*****.**') player_standings = get_top_players() player_info = [] for player_standing in player_standings: player_id = player_standing['playerId'] player_details = get_player(player_id) player_name = player_standing['fullName'] batting_rank = player_standing['battingRank'] bowling_rank = player_standing['bowlingRank'] team_name = player_details['team'] player_type = player_details['type'] player_points = sum( (v for k, v in player_standing.items() if k.endswith('P'))) player_info.append((player_id, player_name, player_type, batting_rank, bowling_rank, player_points, team_name)) #write_updated_top_picks_to_file(json.dumps(player_info)) #write_updated_top_picks_to_file(data) return player_info
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)
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 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 get_second_power_player_for_user(user_id): player = get_squad_details(user_id)['secondPowerPlayer'] return get_player(player).name
def pn(id): return get_player(id).name