def refresh_standings(self): try: if self.config.demo_date: self.standings = mlbgame.standings(datetime(self.year, self.month, self.day, 23, 59, 0, 0)) else: self.standings = mlbgame.standings() except: debug.error("Failed to refresh standings.")
async def standings(ctx): print(braves_id) standings = mlbgame.standings() header = str.format('{0:25} {1:5} {2:5} {3:6} {4:5}\n'.format( 'Team', 'W', 'L', 'L10', 'GB')) divider = '-------------------------------------------------\n' standings_txt = '' for division in standings.divisions: if (division.name == 'NL East'): print('geting NL East stadnings...\n') for team in division.teams: standings_txt += str.format( '{0:25} {1:<5} {2:<5} {3:<6} {4:<5}\n'.format( team.team_full, team.w, team.l, team.last_ten, team.gb)) # send message print(header + divider + standings_txt) await ctx.send(' ```' + header + divider + standings_txt + ' ```')
def test_last_update(self, mock_requests): mock_requests.get(self.standings_url, json=self.standings_json) s = mlbgame.standings(self.date) last_update = self.standings_json['standings_schedule_date']\ ['standings_all_date_rptr']['standings_all_date']\ [0]['queryResults']['created'] self.assertEqual(dateutil.parser.parse(last_update), s.last_update)
def get_total_games(self): all_teams = [] for division in mlbgame.standings().divisions: all_teams.extend(division.teams) for team in all_teams: if team.team_abbrev == 'WSH': total_games = int(team.l) + int(team.w) return total_games
def test_standings(self): standings = mlbgame.standings() self.assertEqual(standings.standings_schedule_date, 'standings_schedule_date') self.assertIsInstance(standings.divisions, list) for division in standings.divisions: self.assertIsInstance(division.name, str) self.assertIsInstance(division.teams, list) for team in division.teams: self.assertIsInstance(team.away, str) self.assertIsInstance(team.clinched_sw, str) self.assertIsInstance(team.division, str) self.assertIsInstance(team.division_champ, str) self.assertIsInstance(team.division_id, int) self.assertIsInstance(team.division_odds, float) self.assertIsInstance(team.elim, (str, int)) self.assertIsInstance(team.elim_wildcard, (str, int)) self.assertIsInstance(team.extra_inn, str) self.assertIsInstance(team.file_code, str) self.assertIsInstance(team.gb, (str, float)) self.assertIsInstance(team.gb_wildcard, (str, float)) self.assertIsInstance(team.home, str) self.assertIsInstance(team.interleague, str) self.assertIsInstance(team.is_wildcard_sw, str) self.assertIsInstance(team.l, int) self.assertIsInstance(team.last_ten, str) self.assertIsInstance(team.one_run, str) self.assertIsInstance(team.opp_runs, int) self.assertIsInstance(team.pct, (float, str)) self.assertIsInstance(team.place, int) self.assertIsInstance(team.playoff_odds, float) self.assertIsInstance(team.playoff_points_sw, str) self.assertIsInstance(team.playoffs_flag_milb, str) self.assertIsInstance(team.playoffs_flag_mlb, str) self.assertIsInstance(team.playoffs_sw, str) self.assertIsInstance(team.points, str) self.assertIsInstance(team.runs, int) self.assertIsInstance(team.sit_code, str) self.assertIsInstance(team.streak, str) self.assertIsInstance(team.team_abbrev, str) self.assertIsInstance(team.team_full, str) self.assertIsInstance(team.team_id, int) self.assertIsInstance(team.team_short, str) self.assertIsInstance(team.vs_central, str) self.assertIsInstance(team.vs_division, str) self.assertIsInstance(team.vs_east, str) self.assertIsInstance(team.vs_left, str) self.assertIsInstance(team.vs_right, str) self.assertIsInstance(team.vs_west, str) self.assertIsInstance(team.w, int) self.assertIsInstance(team.wild_card, str) self.assertIsInstance(team.wildcard_odds, float) self.assertIsInstance(team.x_wl, str) self.assertIsInstance(team.x_wl_seas, str) mlbgame.data.STANDINGS_URL = '{0}' self.assertRaises(ValueError, lambda: mlbgame.data.get_standings(datetime.now()))
def __init__(self,parent): #Init data grab self.teams = mlbgame.teams() self.standings = mlbgame.standings() #Init vars self.teamselect = StringVar(window) self.gamedate = StringVar(window) #Init navigation self.navigation() self.show_calendar()
def populate_data(): divisions = mlbgame.standings().divisions todays_games = mlbgame.day(datetime.now().year, datetime.now().month, datetime.now().day) for division in divisions: for team in division.teams: t = TeamMapper(divisions, todays_games, abbreviation=team.team_abbrev) t.find_team() teams.append(t.team) return teams
def looper(): #os.system('cls') threading.Timer(10.0, looper).start() gameday = datetime.datetime.now() # tomorrow = gameday - datetime.timedelta(1) noGameFound = True while noGameFound: #check for game gameday if len( mlbgame.day(gameday.year, gameday.month, gameday.day, home='Red Sox', away='Red Sox')) != 0: game = mlbgame.day(gameday.year, gameday.month, gameday.day, home='Red Sox', away='Red Sox')[0] noGameFound = False #if no game on the current day check on the next day else: gameday += datatime.timedelta(1) home_team = game.home_team away_team = game.away_team standings = mlbgame.standings() alEast = standings.divisions[3] #game is over, display final score if (game.game_status == "FINAL"): printStandings(alEast) printFinalScore(game) printTweets() #display upcoming game info + standings elif (game.game_status == "PRE_GAME"): printStandings(alEast) printUpcomingGame(game) printTweets() #game is on, display live game info else: printCurrentGame(game)
def looper(): #os.system('cls') threading.Timer(10.0, looper).start() gameday = datetime.datetime.now() # tomorrow = gameday - datetime.timedelta(1) noGameFound = True while noGameFound: #check for game gameday if len(mlbgame.day(gameday.year, gameday.month, gameday.day, home='Red Sox', away = 'Red Sox')) != 0: game = mlbgame.day(gameday.year, gameday.month, gameday.day, home='Red Sox', away = 'Red Sox')[0] noGameFound = False #if no game on the current day check on the next day else: gameday += datatime.timedelta(1) home_team = game.home_team away_team = game.away_team standings = mlbgame.standings() alEast = standings.divisions[3] #game is over, display final score if(game.game_status == "FINAL"): printStandings(alEast) printFinalScore(game) printTweets() #display upcoming game info + standings elif(game.game_status == "PRE_GAME"): printStandings(alEast) printUpcomingGame(game) printTweets() #game is on, display live game info else: printCurrentGame(game)
def refresh_standings(self): try: self.standings = mlbgame.standings() except: debug.error("Failed to refresh standings.")
matrixOptions = led_matrix_options(args) # Initialize the matrix matrix = RGBMatrix(options = matrixOptions) canvas = matrix.CreateFrameCanvas() # Read scoreboard options from config.json if it exists config = ScoreboardConfig("config.json") debug.set_debug_status(config) # Render the current standings or today's games depending on # the provided arguments now = datetime.datetime.now() year = now.year month = now.month day = now.day if config.display_standings: standings = mlbgame.standings(datetime.datetime(year, month, day)) division = next(division for division in standings.divisions if division.name == config.preferred_division) renderers.standings.render(matrix, matrix.CreateFrameCanvas(), division) else: while True: games = mlbgame.games(year, month, day) if not len(games): renderers.offday.render(matrix, matrix.CreateFrameCanvas()) else: # The mlbgame API returns a 2D array with the list of games as the first index, # hence the 'games[0]' GameRenderer(matrix, matrix.CreateFrameCanvas(), games[0], config).render()
def test_standings_json(self, mock_requests): mock_requests.get(self.standings_url, json=self.standings_json) s = mlbgame.standings(self.date) self.assertEqual(s.standings_json, self.standings_json)
def test_divisions_is_list(self, mock_requests): mock_requests.get(self.standings_url, json=self.standings_json) s = mlbgame.standings(self.date) self.assertIsInstance(s.divisions, list)
def test_historical_standings_url(self): s = mlbgame.standings(self.hist_date) self.assertEqual(s.standings_url, self.hist_standings_url)
def test_standings_url(self): s = mlbgame.standings(self.date) self.assertEqual(s.standings_url, self.standings_url)
def test_standings_historical(self): date = datetime(2016, 6, 1) standings = mlbgame.standings(date) self.assertEqual(standings.standings_schedule_date, 'historical_standings_schedule_date') self.assertIsInstance(standings.divisions, list) for division in standings.divisions: self.assertIsInstance(division.name, str) self.assertIsInstance(division.teams, list) if division.name == 'NL West': d = division for team in division.teams: self.assertIsInstance(team.away, str) self.assertIsInstance(team.clinched_sw, str) self.assertIsInstance(team.division, str) self.assertIsInstance(team.division_champ, str) self.assertIsInstance(team.division_id, int) self.assertIsInstance(team.division_odds, float) self.assertIsInstance(team.elim, (str, int)) self.assertIsInstance(team.elim_wildcard, (str, int)) self.assertIsInstance(team.extra_inn, str) self.assertIsInstance(team.file_code, str) self.assertIsInstance(team.gb, (str, float)) self.assertIsInstance(team.gb_wildcard, (str, float)) self.assertIsInstance(team.home, str) self.assertIsInstance(team.interleague, str) self.assertIsInstance(team.is_wildcard_sw, str) self.assertIsInstance(team.l, int) self.assertIsInstance(team.last_ten, str) self.assertIsInstance(team.one_run, str) self.assertIsInstance(team.opp_runs, int) self.assertIsInstance(team.pct, float) self.assertIsInstance(team.place, int) self.assertIsInstance(team.playoff_odds, float) self.assertIsInstance(team.playoff_points_sw, str) self.assertIsInstance(team.playoffs_flag_milb, str) self.assertIsInstance(team.playoffs_flag_mlb, str) self.assertIsInstance(team.playoffs_sw, str) self.assertIsInstance(team.points, str) self.assertIsInstance(team.runs, int) self.assertIsInstance(team.sit_code, str) self.assertIsInstance(team.streak, str) self.assertIsInstance(team.team_abbrev, str) self.assertIsInstance(team.team_full, str) self.assertIsInstance(team.team_id, int) self.assertIsInstance(team.team_short, str) self.assertIsInstance(team.vs_central, str) self.assertIsInstance(team.vs_division, str) self.assertIsInstance(team.vs_east, str) self.assertIsInstance(team.vs_left, str) self.assertIsInstance(team.vs_right, str) self.assertIsInstance(team.vs_west, str) self.assertIsInstance(team.w, int) self.assertIsInstance(team.wild_card, str) self.assertIsInstance(team.wildcard_odds, float) self.assertIsInstance(team.x_wl, str) self.assertIsInstance(team.x_wl_seas, str) if team.file_code == 'sf': t = team division = d self.assertEqual(division.name, 'NL West') team = t self.assertEqual(team.away, '17-11') self.assertEqual(team.clinched_sw, 'N') self.assertEqual(team.division, 'National League West') self.assertEqual(team.division_champ, 'Y') self.assertEqual(team.division_id, 203) self.assertEqual(team.division_odds, 54.4) self.assertEqual(team.elim, '-') self.assertEqual(team.elim_wildcard, '') self.assertEqual(team.extra_inn, '4-3') self.assertEqual(team.file_code, 'sf') self.assertEqual(team.gb, '-') self.assertEqual(team.gb_wildcard, '') self.assertEqual(team.home, '16-11') self.assertEqual(team.interleague, '1-2') self.assertEqual(team.is_wildcard_sw, 'Y') self.assertEqual(team.l, 22) self.assertEqual(team.last_ten, '0-0') self.assertEqual(team.one_run, '12-6') self.assertEqual(team.opp_runs, 220) self.assertEqual(team.pct, .6) self.assertEqual(team.place, 1) self.assertEqual(team.playoff_odds, 77.1) self.assertEqual(team.playoff_points_sw, 'N') self.assertEqual(team.playoffs_flag_milb, '') self.assertEqual(team.playoffs_flag_mlb, '') self.assertEqual(team.playoffs_sw, 'N') self.assertEqual(team.points, '') self.assertEqual(team.runs, 242) self.assertEqual(team.sit_code, 'h0') self.assertEqual(team.streak, 'L1') self.assertEqual(team.team_abbrev, 'SF') self.assertEqual(team.team_full, 'San Francisco Giants') self.assertEqual(team.team_id, 137) self.assertEqual(team.team_short, 'San Francisco') self.assertEqual(team.vs_central, '6-3') self.assertEqual(team.vs_division, '22-12') self.assertEqual(team.vs_east, '4-5') self.assertEqual(team.vs_left, '11-8') self.assertEqual(team.vs_right, '22-14') self.assertEqual(team.vs_west, '22-12') self.assertEqual(team.w, 33) self.assertEqual(team.wild_card, 'N') self.assertEqual(team.wildcard_odds, 22.7) self.assertEqual(team.x_wl, '30-25') self.assertEqual(team.x_wl_seas, '88-74') mlbgame.data.STANDINGS_HISTORICAL_URL = '{0}' self.assertRaises( ValueError, lambda: mlbgame.data.get_historical_standings(datetime.now()))
matrixOptions = led_matrix_options(args) # Initialize the matrix matrix = RGBMatrix(options=matrixOptions) canvas = matrix.CreateFrameCanvas() # Read scoreboard options from config.json if it exists config = ScoreboardConfig("config.json") debug.set_debug_status(config) # Render the current standings or today's games depending on # the provided arguments now = datetime.datetime.now() year = now.year month = now.month day = now.day if config.display_standings: standings = mlbgame.standings(datetime.datetime(year, month, day)) division = next(division for division in standings.divisions if division.name == config.preferred_division) renderers.standings.render(matrix, matrix.CreateFrameCanvas(), division) else: while True: games = mlbgame.day(year, month, day) if not len(games): renderers.offday.render(matrix, matrix.CreateFrameCanvas()) else: GameRenderer(matrix, matrix.CreateFrameCanvas(), games, config).render()
def refresh_standings(self): try: self.standings = mlbgame.standings() except: debug.error("Failed to refresh standings.")
from utils import args, led_matrix_options from renderer import render_games, render_standings, render_offday import datetime import mlbgame args = args() # Check for led configuration arguments matrixOptions = led_matrix_options(args) # Initialize the matrix and fill it in with a dark blue color matrix = RGBMatrix(options=matrixOptions) canvas = matrix.CreateFrameCanvas() if args.standings: standings = mlbgame.standings(datetime.datetime(2017, 9, 30)) division = next(division for division in standings.divisions if division.name == args.standings) render_standings(matrix, canvas, division) else: now = datetime.datetime.now() year = now.year month = now.month day = now.day # TODO: Uncomment once the season starts, testing with random games for now # Uncomment now if you want to see the offday/offseason message # games = mlbgame.games(year, month, day) games = mlbgame.games(2017, 9, 30) if not len(games): render_offday(matrix, canvas) else: