Refining Pirates

This commit is contained in:
2026-05-24 21:04:24 -04:00
parent 897f41da72
commit da0bbbf918
3 changed files with 48 additions and 5 deletions

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@ lib
lib64
__pycache__
old
Scripts
pyvenv.cfg

47
mlb.py
View File

@@ -1,5 +1,43 @@
import statsapi
import datetime
import pytz
def process_game(game):
results = ""
useastern_timezone = pytz.timezone("US/Eastern")
if game["home_name"] == "Pittsburgh Pirates": # home game
score_pirates = game["home_score"]
score_other = game["away_score"]
results += "vs "+game["away_name"]
else:
score_pirates = game["away_score"]
score_other = game["home_score"]
results += "at "+game["home_name"]
if game["status"] != "Scheduled":
if game["status"] == "Final":
if score_pirates > score_other:
results += " Pirates won"
else:
results += " Pirates lost"
else: # game in progress
if score_pirates > score_other:
results += " Pirates winning"
else:
results += " Pirates losing"
results += " "+str(game["away_score"])+" - "+str(game["home_score"])
if game["status"] != "Final":
gamedate = datetime.datetime.strptime(game["game_datetime"],"%Y-%m-%dT%H:%M:%SZ")
gamedateutc = gamedate.replace(tzinfo=datetime.timezone.utc)
results+= " "+gamedateutc.astimezone(tz=useastern_timezone).strftime("%I:%M %p")
if game["national_broadcasts"]:
nb = ""
for b in game["national_broadcasts"]:
if nb:
nb += ", "
nb += b
results += " (on "+nb+")"
results += " ("+game["status"]+")"
return results
def get_pirates():
@@ -10,11 +48,14 @@ def get_pirates():
piratesid = statsapi.lookup_team('pittsburgh')[0]['id']
todaysgame = statsapi.schedule(team=piratesid,date=todaystr)
if todaysgame:
results += todaysgame[0]["summary"]+" "+todaysgame[0]["game_datetime"]+"\n"
results+= "Today: "+process_game(todaysgame[0])+"\n"
#results += todaysgame[0]["summary"]+" "+todaysgame[0]["game_datetime"]+"\n"
#print("todaysgame",todaysgame)
tomorrowsgame = statsapi.schedule(team=piratesid,date=tomorrowstr)
if tomorrowsgame:
dtt = tomorrowsgame[0]["game_datetime"][11:16]
results+= tomorrowsgame[0]["summary"]+" "+tomorrowsgame[0]["game_datetime"]+"\n"
results+= "Tomorrow: "+process_game(tomorrowsgame[0])+"\n"
#dtt = tomorrowsgame[0]["game_datetime"][11:16]
#results+= tomorrowsgame[0]["summary"]+" "+tomorrowsgame[0]["game_datetime"]+"\n"
return results
if __name__ == '__main__':

View File

@@ -1,5 +1,5 @@
home = /usr/bin
home = C:\Users\tim\AppData\Roaming\uv\python\cpython-3.13.2-windows-x86_64-none
implementation = CPython
uv = 0.11.15
version_info = 3.12.3
version_info = 3.13.2
include-system-site-packages = false