Пример #1
0
    def test_league_box_scores(self):
        league = League(411647, 2019)
        final_matchup = league.box_scores()[0]
        middle_matchup = league.box_scores(matchup_period=7)[0]
        # same matchup period but single scoring period
        scoring_period_matchup = league.box_scores(scoring_period=48, matchup_total=False)[0]

        self.assertEqual(final_matchup.home_score, 4240.0)
        self.assertEqual(final_matchup.away_lineup[0].points, 156.0)

        self.assertEqual(middle_matchup.home_score, 1234.0)
        self.assertEqual(middle_matchup.away_lineup[0].points, 12.5)

        self.assertEqual(scoring_period_matchup.home_score, 234.0)
        self.assertEqual(scoring_period_matchup.away_lineup[0].points, 0)
Пример #2
0
# 4. Notify if somone will leave a roster spot open because of an eligibility requirement
# 5. Use a main function
######

# Turn off requests verification warning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# Get league and team names
cookies = {
    'espn_s2':
    'AEAw9%2Fuxfn6t5tJAomwsmBkwmDu7u35FSUIn%2FDEa1zernBO7QjiTwcVjZTk5ZmbsckQ6Bwe9g5htKyE%2B1VHcdGKe%2BKpnEpcO6wuZa3%2BS1k2RBjsH%2F5wwU4%2BGsMNJbCxJ%2BjrxScV0cAlcSVNBDArKkVHSy6aC5Wjdl86Sc0xJzjrw0NGmCWwCNCQlp%2FYj%2B0WZEk87BCatAaVHsc1Ojwa%2FJ5ce6CMAY2dlhxjCUX3LrY3qTxTCqOftpSjfN51aaiYX5aeYHwWBShNhTnsTI%2Bo5FOi9',
    'swid': '{9404E72D-02B1-41C9-84E7-2D02B191C9FC}'
}

league = League(league_id=79672,
                year=2022,
                espn_s2=cookies['espn_s2'],
                swid=cookies['swid'])
teams = league.teams

day = datetime.datetime.today()
#day = datetime.datetime(2021, 11, 29)
start, end = getStartEnd(day)
week = getWeekNumber(day)
current_week = league.current_week
matchups = league.scoreboard(week)
box_scores = league.box_scores()  # box_scores class
weekly_schedule = getWeeklySchedule(start, end, cookies, PRO_TEAM_MAP)
projections = {}

# Loop over teams
for team in league.teams:
Пример #3
0
    def test_league_init(self):
        league = League(411647, 2019)

        self.assertEqual(league.scoringPeriodId, 178)
Пример #4
0
    def test_past_league_scoreboard(self):
        league = League(411647, 2017)
        scores = league.scoreboard()

        self.assertEqual(scores[0].home_final_score, 4211.0)
        self.assertEqual(scores[0].away_final_score, 3548.5)
Пример #5
0
    def test_past_league(self):
        league = League(411647, 2017)

        self.assertEqual(league.scoringPeriodId, 170)
Пример #6
0
    def test_league_scoreboard(self):
        league = League(411647, 2019)
        scores = league.scoreboard()

        self.assertEqual(scores[0].home_final_score, 4240.0)
        self.assertEqual(scores[0].away_final_score, 2965.0)
Пример #7
0
    def test_past_league_scoreboard(self):
        league = League(411647, 2017)
        scores = league.scoreboard()

        self.assertTrue(scores[0].home_final_score > 0)
        self.assertTrue(scores[0].away_final_score > 0)
Пример #8
0
    def test_league_free_agents(self):
        league = League(411647, 2019)
        free_agents = league.free_agents()

        self.assertNotEqual(len(free_agents), 0)
Пример #9
0
def bot_main(function):
    try:
        bot_id = os.environ["BOT_ID"]
    except KeyError:
        bot_id = 1

    try:
        slack_webhook_url = os.environ["SLACK_WEBHOOK_URL"]
    except KeyError:
        slack_webhook_url = 1

    try:
        discord_webhook_url = os.environ["DISCORD_WEBHOOK_URL"]
    except KeyError:
        discord_webhook_url = 1

    league_id = os.environ["LEAGUE_ID"]

    try:
        year = int(os.environ["LEAGUE_YEAR"])
    except KeyError:
        year=2020

    try:
        swid = os.environ["SWID"]
    except KeyError:
        swid='{1}'

    if swid.find("{",0) == -1:
        swid = "{" + swid
    if swid.find("}",-1) == -1:
        swid = swid + "}"

    try:
        espn_s2 = os.environ["ESPN_S2"]
    except KeyError:
        espn_s2 = '1'

    try:
        espn_username = os.environ["ESPN_USERNAME"]
    except KeyError:
        espn_username = '******'

    try:
        espn_password = os.environ["ESPN_PASSWORD"]
    except KeyError:
        espn_password = '******'

    try:
        test = os.environ["TEST"]
    except KeyError:
        test = False

    try:
        top_half_scoring = os.environ["TOP_HALF_SCORING"]
    except KeyError:
        top_half_scoring = False

    bot = GroupMeBot(bot_id)
    slack_bot = SlackBot(slack_webhook_url)
    discord_bot = DiscordBot(discord_webhook_url)

    if swid == '{1}' and espn_s2 == '1': # and espn_username == '1' and espn_password == '1':
        league = League(league_id=league_id, year=year)
    else:
        league = League(league_id=league_id, year=year, espn_s2=espn_s2, swid=swid)
#    if espn_username and espn_password:
#        league = League(league_id=league_id, year=year, username=espn_username, password=espn_password)

    if test:
        print(get_matchups(league))
        print(get_scoreboard_short(league))
        print(get_projected_scoreboard(league))
        print(get_close_scores(league))
        print(get_power_rankings(league))
        print(get_scoreboard_short(league))
        print(get_standings(league, top_half_scoring))
        function="get_final"
        bot.send_message("Testing")
        slack_bot.send_message("Testing")
        discord_bot.send_message("Testing")

    text = ''
    if function=="get_matchups":
        text = get_matchups(league)
        text = text + "\n\n" + get_projected_scoreboard(league)
    elif function=="get_scoreboard_short":
        text = get_scoreboard_short(league)
        text = text + "\n\n" + get_projected_scoreboard(league)
    elif function=="get_projected_scoreboard":
        text = get_projected_scoreboard(league)
    elif function=="get_close_scores":
        text = get_close_scores(league)
    elif function=="get_power_rankings":
        text = get_power_rankings(league)
    elif function=="get_trophies":
        text = get_trophies(league)
    elif function=="get_standings":
        text = get_standings(league, top_half_scoring)
    elif function=="get_final":
        # on Tuesday we need to get the scores of last week
        week = league.current_week - 1
        text = "Final " + get_scoreboard_short(league, week=week)
        text = text + "\n\n" + get_trophies(league, week=week)
    elif function=="init":
        try:
            text = os.environ["INIT_MSG"]
        except KeyError:
            #do nothing here, empty init message
            pass
    else:
        text = "Something happened. HALP"

    if text != '' and not test:
        bot.send_message(text)
        slack_bot.send_message(text)
        discord_bot.send_message(text)

    if test:
        #print "get_final" function
        print(text)
Пример #10
0

#-------------------------

n_players = 100
starttime = time.time()
# Turn off requests verification warning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Get league and team names
cookies = {
    'espn_s2':
    'AEAw9%2Fuxfn6t5tJAomwsmBkwmDu7u35FSUIn%2FDEa1zernBO7QjiTwcVjZTk5ZmbsckQ6Bwe9g5htKyE%2B1VHcdGKe%2BKpnEpcO6wuZa3%2BS1k2RBjsH%2F5wwU4%2BGsMNJbCxJ%2BjrxScV0cAlcSVNBDArKkVHSy6aC5Wjdl86Sc0xJzjrw0NGmCWwCNCQlp%2FYj%2B0WZEk87BCatAaVHsc1Ojwa%2FJ5ce6CMAY2dlhxjCUX3LrY3qTxTCqOftpSjfN51aaiYX5aeYHwWBShNhTnsTI%2Bo5FOi9',
    'swid': '{9404E72D-02B1-41C9-84E7-2D02B191C9FC}'
}
kt_league = League(league_id=79672,
                   year=2022,
                   espn_s2=cookies['espn_s2'],
                   swid=cookies['swid'])
client = Client("ifGbTzg7JO0Ij4C2KkJ2")

# Initialize activity and player list
tmp_kt_act = kt_league.recent_activity()[0]
player_list = buildPlayerList()  # Get the Free Agent stats

while True:

    try:  # Get the recent activity in the league
        activity_kt = kt_league.recent_activity()
    except (Timeout, SSLError, ReadTimeoutError, ConnectionError) as e:
        print("Network error occurred. Keep calm and carry on.")
    except Exception as e:
        print("Unexpected error!")
Пример #11
0
from espn_api.basketball import League
import json


LEAGUE_ID = 2142217092
YEAR = 2021
ESPN_2 = "AECox3HQX41Ekc%2Bjyoa6Vj4bWoIqI3uhRpyMRAhNIDKCary6Q3Q0IFToSQahGqCar%2F%2BaJq0UlQs%2B%2BoHjndhneXswVf%2BF1zLbBbJ2AwKd%2F1hZUY1Kjv884%2FElh4e19tNeK9DqAAyr9GYWJ0Fw5Z%2FUYKWdI48gCD1rR4CjKiZgpTqgk1Tm9ifkfC0TyzDYa%2Bda4a4VvLdsS6hYMuvCJm9acLENgXYBTqvZqBeOm7UySYVCw8lqwyjacW8gnpcw6T9igzOTlDxsjW6uYhu1yvbSvTp7"
SWID = "0FA8E20F-267F-4A5E-9630-7D28BABEF81C"

with open('server/schedule.json') as file:
    schedule = json.load(file)



league = League(league_id=2142217092, year = 2021, espn_s2=ESPN_2, swid=SWID)
box = league.box_scores()
week  = league.get_team_data(1).wins + league.get_team_data(1).losses + league.get_team_data(1).ties + 3
total_games = week - 3
matchups = league.scoreboard(week)
print(matchups)
team_points = {
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0

}

team_names = {
Пример #12
0
from math import sqrt
from espn_api.basketball import League
from termcolor import colored

#vars#
playersDic = {}
statsDic = {}
minsList = []
xAxis = [1, 2, 3]
slope = 0
count = 0


# Intializing myLeague : your league_id: int, your year: int, your espn_s2=None, your swid=None #
mainLeague = League('league_id', 'year',
                    'espn_s2',
                    'swid')

listOfTeamsPlaying = mainLeague.standings()
agents = mainLeague.free_agents(size=200)


# Function for Fantasy Points (Last 15 Days) #
def myPoints(player):
    points = 0
    points += player.__getattribute__('stats')['032021']['avg']['FGM'] * 2
    points -= player.__getattribute__('stats')['032021']['avg']['FGM'] - \
              player.__getattribute__('stats')['032021']['avg']['FGA']
    points += player.__getattribute__('stats')['032021']['avg']['FTM']
    points -= player.__getattribute__('stats')['032021']['avg']['FTA'] - \
              player.__getattribute__('stats')['032021']['avg']['FTM']
Пример #13
0
from espn_api.basketball import League

LEAGUE_ID = 2142217092
YEAR = 2021
ESPN_2 = "AECox3HQX41Ekc%2Bjyoa6Vj4bWoIqI3uhRpyMRAhNIDKCary6Q3Q0IFToSQahGqCar%2F%2BaJq0UlQs%2B%2BoHjndhneXswVf%2BF1zLbBbJ2AwKd%2F1hZUY1Kjv884%2FElh4e19tNeK9DqAAyr9GYWJ0Fw5Z%2FUYKWdI48gCD1rR4CjKiZgpTqgk1Tm9ifkfC0TyzDYa%2Bda4a4VvLdsS6hYMuvCJm9acLENgXYBTqvZqBeOm7UySYVCw8lqwyjacW8gnpcw6T9igzOTlDxsjW6uYhu1yvbSvTp7"
SWID = "0FA8E20F-267F-4A5E-9630-7D28BABEF81C"

league = League(league_id=2142217092, year=2021, espn_s2=ESPN_2, swid=SWID)

matchups = league.scoreboard(9)

matchup = matchups[0]

team = matchup.home_team

for i in range(len(team.roster)):
    print(team.roster[i].injuryStatus)