Trying to avoid error propagation from Google Weather overuse

This commit is contained in:
2026-05-25 01:58:52 +00:00
parent da0bbbf918
commit f40662ab27
3 changed files with 22 additions and 15 deletions

22
mlb.py
View File

@@ -2,9 +2,8 @@ import statsapi
import datetime
import pytz
def process_game(game):
def process_game(game,mytz):
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"]
@@ -16,19 +15,19 @@ def process_game(game):
if game["status"] != "Scheduled":
if game["status"] == "Final":
if score_pirates > score_other:
results += " Pirates won"
results += ", Pirates won"
else:
results += " Pirates lost"
results += ", Pirates lost"
else: # game in progress
if score_pirates > score_other:
results += " Pirates winning"
results += ", Pirates winning"
else:
results += " Pirates losing"
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")
results+= " "+gamedateutc.astimezone(tz=mytz).strftime("%I:%M %p")
if game["national_broadcasts"]:
nb = ""
for b in game["national_broadcasts"]:
@@ -41,19 +40,20 @@ def process_game(game):
def get_pirates():
useastern_timezone = pytz.timezone("US/Eastern")
results = ""
todaystr = datetime.datetime.now().strftime("%Y-%m-%d")
tomorrow = datetime.datetime.now()+datetime.timedelta(days=1)
todaystr = datetime.datetime.now(tz=useastern_timezone).strftime("%Y-%m-%d")
tomorrow = datetime.datetime.now(tz=useastern_timezone)+datetime.timedelta(days=1)
tomorrowstr = tomorrow.strftime("%Y-%m-%d")
piratesid = statsapi.lookup_team('pittsburgh')[0]['id']
todaysgame = statsapi.schedule(team=piratesid,date=todaystr)
if todaysgame:
results+= "Today: "+process_game(todaysgame[0])+"\n"
results+= "Today: "+process_game(todaysgame[0],useastern_timezone)+"\n"
#results += todaysgame[0]["summary"]+" "+todaysgame[0]["game_datetime"]+"\n"
#print("todaysgame",todaysgame)
tomorrowsgame = statsapi.schedule(team=piratesid,date=tomorrowstr)
if tomorrowsgame:
results+= "Tomorrow: "+process_game(tomorrowsgame[0])+"\n"
results+= "Tomorrow: "+process_game(tomorrowsgame[0],useastern_timezone)+"\n"
#dtt = tomorrowsgame[0]["game_datetime"][11:16]
#results+= tomorrowsgame[0]["summary"]+" "+tomorrowsgame[0]["game_datetime"]+"\n"
return results