Skip to content

Commit

Permalink
Fixed two critical issues.
Browse files Browse the repository at this point in the history
- Fixed a bug in `get_milb_schedule.py` that would cause the script to crash and burn due because it looped through a `datetime` object.
- Refactored `get_milb_pbp.py` to allow someone to download High-A, Single-A, and/or Low-A/Short Season A PBP data.
  • Loading branch information
armstjc committed Jul 22, 2023
1 parent b8ee7e4 commit 8fe5d78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions get_milb_pbp.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,12 @@ def get_month_milb_pbp(season: int, month: int, level="AAA", cache_data=False, c
sched_df = get_milb_schedule(season, 'AAA')
if (level.lower() == 'aa') or (level.lower() == 'double-a') or (level.lower() == 'double a'):
sched_df = get_milb_schedule(season, 'AA')
elif (level.lower() == 'a+') or (level.lower() == 'high-a') or (level.lower() == 'high a'):
sched_df = get_milb_schedule(season, 'A+')
if (level.lower() == 'a') or (level.lower() == 'single-a') or (level.lower() == 'single-a'):
sched_df = get_milb_schedule(season, 'A')
elif (level.lower() == 'a-') or (level.lower() == 'short-a') or (level.lower() == 'short a'):
sched_df = get_milb_schedule(season, 'A-')
if (level.lower() == 'rk') or (level.lower() == 'rok') or (level.lower() == 'rookie'):
sched_df = get_milb_schedule(season, 'AA')

Expand All @@ -820,7 +824,7 @@ def get_month_milb_pbp(season: int, month: int, level="AAA", cache_data=False, c
game_id=game_id, cache_data=cache_data, cache_dir=cache_dir)
pbp_df = pd.concat([pbp_df, game_df], ignore_index=True)

if save == True:
if save == True and len(pbp_df) > 0:
pbp_df.to_csv(
f'pbp/{season}_{month}_{level.lower()}_pbp.csv', index=False)
return pbp_df
Expand All @@ -829,4 +833,7 @@ def get_month_milb_pbp(season: int, month: int, level="AAA", cache_data=False, c
if __name__ == "__main__":
print('starting up')
# get_milb_game_pbp(725505, cache_data=True, cache_dir='D:/')
get_month_milb_pbp(2023, 4, level="A", cache_data=True, cache_dir='D:/')
season = 2023
for i in range(3, 7):
get_month_milb_pbp(season, i, level="A",
cache_data=True, cache_dir='D:/')
2 changes: 1 addition & 1 deletion get_milb_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def get_milb_schedule(season: int, level="AAA", cache_data=False, cache_dir=""):

if __name__ == "__main__":
now = datetime.now()
for season in range(now, now+1):
for season in range(now.year, now.year+1):
try:
print(f'Getting {season} Triple-A schedules.')
aaa_df = get_milb_schedule(season, 'aaa')
Expand Down

0 comments on commit 8fe5d78

Please sign in to comment.