Ejemplo n.º 1
0
    bot_type = os.environ["BOT_TYPE"]
    league_id = os.environ["LEAGUE_ID"]

    # Check if the user specified the close game num. Default is 20.
    try:
        close_num = os.environ["CLOSE_NUM"]
    except:
        close_num = 20

    starting_date = pendulum.datetime(STARTING_YEAR, STARTING_MONTH,
                                      STARTING_DAY)

    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)

    bot.send(get_welcome_string)  # inital message to send
    schedule.every().thursday.at("19:00").do(
        bot.send, get_matchups_string,
        league_id)  # Matchups Thursday at 4:00 pm ET
    schedule.every().friday.at("12:00").do(
        bot.send, get_scores_string, league_id)  # Scores Friday at 12 pm ET
    schedule.every().sunday.at("23:00").do(
        bot.send, get_close_games_string, league_id,
Ejemplo n.º 2
0
def get_player_key(search_string, requestor, name_key_switch):
    players = Players().get_all_players()
    bot_type = os.environ["BOT_TYPE"]

    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)

    found_players = []
    if name_key_switch == 0:
        for player_id in players:
            player = players[player_id]
            try:
                token_set_ratio = fuzz.token_set_ratio(search_string, player["search_full_name"])
                try:
                    injury_status = player["injury_status"]
                except:
                    injury_status = None
                if search_string in player["search_full_name"]:
                    found_players.append((player_id, player["full_name"], player["position"], player["team"], injury_status))
                elif token_set_ratio > 79:
                    found_players.append((player_id, player["full_name"], player["position"], player["team"], injury_status))
            except:
                pass
            if player["position"] == "DEF":
                search_name = player["first_name"].lower() + player["last_name"].lower()
                search_name = search_name.replace(" ","")
                full_name_clean = player["first_name"] + " " + player["last_name"]
                def_ratio = fuzz.ratio(search_string, search_name)
                try:
                    injury_status = player["injury_status"]
                except:
                    injury_status = None
                if def_ratio > 54:
                    found_players.append((player_id, full_name_clean, player["position"], player["team"], injury_status))
        if len(found_players) > 1:
            text = "Which player are you looking for?\n\n"
            for p in found_players:
                text += "for {} ({} - {}) - reply {}\n\n".format(p[1], p[2], p[3], p[0])
            bot.send(send_any_string, text)
            return "True"
        elif len(found_players) == 1:
            get_player_stats(found_players[0])
            return "False"
        elif len(found_players) == 0:
            bot.send(send_any_string, 'Player not found')
            return "False"
    elif name_key_switch == 1:
        player = players[search_string]
        if player["position"] == "DEF":
            full_name_clean = player["first_name"] + " " + player["last_name"]
            try:
                injury_status = player["injury_status"]
            except:
                injury_status = None
            found_players.append((search_string, full_name_clean, player["position"], player["team"], injury_status))
        else:
            try:
                injury_status = player["injury_status"]
            except:
                injury_status = None
            found_players.append((search_string, player["full_name"], player["position"], player["team"], injury_status))
        get_player_stats(found_players[0])
        return "False"
Ejemplo n.º 3
0
def get_player_stats(search_object):

    today = pendulum.today()
    starting_date = pendulum.datetime(STARTING_YEAR, STARTING_MONTH, STARTING_DAY)
    if starting_date >= today:
        year = STARTING_YEAR
    else:
        year = int(STARTING_YEAR) - 1
    stats = Stats(). get_all_stats("regular",year)

    bot_type = os.environ["BOT_TYPE"]


    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)
    stats_run = True
    player_id = search_object[0]
    player_name = search_object[1]
    position = search_object[2]
    team = search_object[3]
    if search_object[4] == None:
        injury_status = 'Active'
    else:
        injury_status = search_object[4]
    try:
        player = stats[player_id]
    except:
        stats_run = False
        pass
    if position not in ["QB","RB","WR","TE","DEF"]:
        stats_run = False
    if stats_run:
        if position is not "DEF":
            final_string = "{} ({} - {})\n{}\n\n".format(player_name, position, team, injury_status)
        else:
            final_string = "{} ({} - {})\n\n".format(player_name, position, team)

        if position is not "DEF":
            try:
                ga = int(player["gms_active"])
            except:
                ga = 0
                pass
            try:
                gp = int(player["gp"])
            except:
                gp = 0
                pass
            try:
                gs = int(player["gs"])
                pass
            except:
                gs = 0
                pass
            try:
                pts_half_ppr = player["pts_half_ppr"]
            except:
                pts_half_ppr = 0
                pass

            final_string += "Fantasy Points: {}\n\nGames Active: {}\nGames Played: {}\nGames Started: {}\n\n".format(pts_half_ppr, ga, gp, gs)

            try:
                team_snaps = player["tm_off_snp"]
                player_snaps = player["off_snp"]
                snap_perc = round((player_snaps / team_snaps)*100,2)
                final_string += "Snap Share: {}%\n".format(snap_perc)
            except:
                pass

        if "QB" in position:
            #try:
                #rating = player["pass_rtg"]
                #final_string += "Passer Rating: {}\n".format(rating)
            #except:
                #pass
            try:
                pyards = int(player["pass_yd"])
                final_string += "Passing Yards: {}\n".format(pyards)
            except:
                pass
            try:
                ptd = int(player["pass_td"])
                final_string += "Passing TDs: {}\n".format(ptd)
            except:
                pass
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                pass_int = int(player["pass_int"])
                final_string += "Interceptions {}\n".format(pass_int)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
        if "RB" in position:
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
            try:
                catch_perc = round((player["rec"]/player["rec_tgt"])*100,2)
                final_string += "Catch Rate: {}%\n".format(catch_perc)
            except:
                pass
            try:
                rcyards = int(player["rec_yd"])
                final_string += "Receiving Yards: {}\n".format(rcyards)
            except:
                pass
            try:
                rctd = int(player["rec_td"])
                final_string += "Receiving TDs: {}\n".format(rctd)
            except:
                pass
        if "WR" in position:
            try:
                rcyards = int(player["rec_yd"])
                final_string += "Receiving Yards: {}\n".format(rcyards)
            except:
                pass
            try:
                rctd = int(player["rec_td"])
                final_string += "Receiving TDs: {}\n".format(rctd)
            except:
                pass
            try:
                drop_perc = round((player["rec"]/player["rec_tgt"])*100,2)
                final_string += "Catch Rate: {}%\n".format(drop_perc)
            except:
                pass
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
        if "TE" in position:
            try:
                rcyards = int(player["rec_yd"])
                final_string += "Receiving Yards: {}\n".format(rcyards)
            except:
                pass
            try:
                rctd = int(player["rec_td"])
                final_string += "Receiving TDs: {}\n".format(rctd)
            except:
                pass
            try:
                drop_perc = round((player["rec"]/player["rec_tgt"])*100,2)
                final_string += "Catch Rate: {}%\n".format(drop_perc)
            except:
                pass
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
        if "K" in position:
            try:
                fga = int(player["fga"])
                fgm = int(player["fgm"])
                fgperc = round((fgm/fga)*100,2)
                final_string += "FG%: {}\n\nField Goals Attempted: {}\nField Goals Made: {}\n".format(fgperc, fga, fgm)
            except:
                pass
            try:
                fgm = int(player["fgm"])
                final_string += "Field Goals Made: {}\n".format(fgm)
            except:
                pass
            try:
                fgm1 = int(player["fgm_0_19"])
                final_string += "0-19: {}\n".format(fgm1)
            except:
                pass
            try:
                fgm2 = int(player["fgm_20_29"])
                final_string += "20-29: {}\n".format(fgm2)
            except:
                pass
            try:
                fgm3 = int(player["fgm_30_39"])
                final_string += "30-39: {}\n".format(fgm3)
            except:
                pass
            try:
                fgm4 = int(player["fgm_40_49"])
                final_string += "40-49: {}\n".format(fgm4)
            except:
                pass
            try:
                fgm5 = int(player["fgm_50p"])
                final_string += "50+: {}\n".format(fgm5)
            except:
                pass
            try:
                xpa = int(player["xpa"])
                xpm = int(player["xpm"])
                xpperc = round((xpm/xpa)*100,2)
                final_string += "XP%: {}\n\nXP Attempted: {}\nXP Made: {}\n".format(xpperc, xpa, xpm)
            except:
                pass
        if "DEF" in position:
            try:
                td = int(player["td"])
                final_string += "Touchdowns: {}\n".format(td)
            except:
                pass
            try:
                ff = int(player["ff"])
                final_string += "Forced Fumbles: {}\n".format(ff)
            except:
                pass
            try:
                fum_rec = int(player["fum_rec"])
                final_string += "Fumbles Recoved: {}\n".format(fum_rec)
            except:
                pass
            try:
                tkl = int(player["tkl_loss"])
                final_string += "Tackles For Loss: {}\n".format(tkl)
            except:
                pass
            try:
                qbh = int(player["qb_hit"])
                final_string += "QB Hits: {}\n".format(qbh)
            except:
                pass
            try:
                sck = int(player["sack"])
                final_string += "Sacks: {}\n".format(sck)
            except:
                pass
    else:
        if player_name == "Aaron Hernandez":
            final_string = "{} hung himself. Gone Forever! Aaron Hernandez.".format(player_name)
        elif position not in ["QB","RB","WR","TE"]:
            final_string = "I do not do IDP stats"
        else:
            final_string = "No {} stats found for {}".format(year, player_name)

    bot.send(send_any_string, final_string)
Ejemplo n.º 4
0
def get_depth_chart(team, position):
    players = Players().get_all_players()

    bot_type = os.environ["BOT_TYPE"]

    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)

    final_string = "Depth Chart for {} - {}\n\n".format(team, position)
    if position == 'WR':
        lwrdc_num = []
        rwrdc_num = []
        swrdc_num = []
        for player_id in players:
            player = players[player_id]
            if player["team"] == team and player["position"] == position:
                if player["depth_chart_order"] is not None:
                    if player["depth_chart_position"] == 'LWR':
                        lwrdc_num.append(player["depth_chart_order"])
                    elif player["depth_chart_position"] == 'RWR':
                        rwrdc_num.append(player["depth_chart_order"])
                    elif player["depth_chart_position"] == 'SWR':
                        swrdc_num.append(player["depth_chart_order"])
        if len(lwrdc_num) > 0:
            lwrdc_cnt = max(lwrdc_num)
            i =1
            final_string += "WR1:\n"
            while i <= lwrdc_cnt:
                for player_id in players:
                    player = players[player_id]
                    if team == player["team"] and position == player["position"] and player["depth_chart_position"] == 'LWR' and i == player["depth_chart_order"]:
                        final_string += "{}. {}\n".format(i, player["full_name"])
                i += 1
            final_string += "\n"
        if len(rwrdc_num) > 0:
            rwrdc_cnt = max(rwrdc_num)
            i =1
            final_string += "WR2:\n"
            while i <= rwrdc_cnt:
                for player_id in players:
                    player = players[player_id]
                    if team == player["team"] and position == player["position"] and player["depth_chart_position"] == 'RWR' and i == player["depth_chart_order"]:
                        final_string += "{}. {}\n".format(i, player["full_name"])
                i += 1
            final_string += "\n"
        if len(swrdc_num) > 0:
            swrdc_cnt = max(swrdc_num)
            i = 1
            final_string += "WR3:\n"
            while i <= swrdc_cnt:
                for player_id in players:
                    player = players[player_id]
                    if team == player["team"] and position == player["position"] and player["depth_chart_position"] == 'SWR' and i == player["depth_chart_order"]:
                        final_string += "{}. {}\n".format(i, player["full_name"])
                i += 1
            final_string += "\n"
    else:
        dc_num = []
        for player_id in players:
            player = players[player_id]
            if player["team"] == team and player["position"] == position:
                if player["depth_chart_order"] is not None:
                    dc_num.append(player["depth_chart_order"])
        dc_cnt = max(dc_num)
        i = 1
        while i <= dc_cnt:
            for player_id in players:
                player = players[player_id]
                if team == player["team"] and position == player["position"] and i == player["depth_chart_order"]:
                    final_string += "{}. {}\n".format(i, player["full_name"])
            i += 1
    bot.send(send_any_string, final_string)