Refining Pirates
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ lib
|
|||||||
lib64
|
lib64
|
||||||
__pycache__
|
__pycache__
|
||||||
old
|
old
|
||||||
|
Scripts
|
||||||
|
pyvenv.cfg
|
||||||
|
|||||||
47
mlb.py
47
mlb.py
@@ -1,5 +1,43 @@
|
|||||||
import statsapi
|
import statsapi
|
||||||
import datetime
|
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():
|
def get_pirates():
|
||||||
@@ -10,11 +48,14 @@ def get_pirates():
|
|||||||
piratesid = statsapi.lookup_team('pittsburgh')[0]['id']
|
piratesid = statsapi.lookup_team('pittsburgh')[0]['id']
|
||||||
todaysgame = statsapi.schedule(team=piratesid,date=todaystr)
|
todaysgame = statsapi.schedule(team=piratesid,date=todaystr)
|
||||||
if todaysgame:
|
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)
|
tomorrowsgame = statsapi.schedule(team=piratesid,date=tomorrowstr)
|
||||||
if tomorrowsgame:
|
if tomorrowsgame:
|
||||||
dtt = tomorrowsgame[0]["game_datetime"][11:16]
|
results+= "Tomorrow: "+process_game(tomorrowsgame[0])+"\n"
|
||||||
results+= tomorrowsgame[0]["summary"]+" "+tomorrowsgame[0]["game_datetime"]+"\n"
|
#dtt = tomorrowsgame[0]["game_datetime"][11:16]
|
||||||
|
#results+= tomorrowsgame[0]["summary"]+" "+tomorrowsgame[0]["game_datetime"]+"\n"
|
||||||
return results
|
return results
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -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
|
implementation = CPython
|
||||||
uv = 0.11.15
|
uv = 0.11.15
|
||||||
version_info = 3.12.3
|
version_info = 3.13.2
|
||||||
include-system-site-packages = false
|
include-system-site-packages = false
|
||||||
|
|||||||
Reference in New Issue
Block a user