From 897f41da72b3c3d4c76f23da1cbfe9edb5ab9568 Mon Sep 17 00:00:00 2001 From: Tim Meneely Date: Sun, 24 May 2026 23:42:36 +0000 Subject: [PATCH] First pass at Pirates --- .gitignore | 1 + getweather.py | 28 ---------------------------- imagegen.py | 5 +++-- mlb.py | 29 +++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 5 files changed, 37 insertions(+), 30 deletions(-) delete mode 100644 getweather.py create mode 100644 mlb.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index eb102d9..868d255 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bin lib lib64 __pycache__ +old diff --git a/getweather.py b/getweather.py deleted file mode 100644 index 148b4a4..0000000 --- a/getweather.py +++ /dev/null @@ -1,28 +0,0 @@ -import python_weather -import datetime -import asyncio -import string - - -async def getweather() -> string: - async with python_weather.Client(unit=python_weather.IMPERIAL) as client: - theweather="" - # Fetch a weather forecast from a city. - weather = await client.get('Franklin Park PA') - #weather = await client.get('Pittsburgh') - # Fetch weather forecast for upcoming days. - for daily in weather: - if daily.date == datetime.datetime.today().date(): - theweather += "Today's forecast: High: "+str(daily.highest_temperature)+" F, Low: "+str(daily.lowest_temperature)+" F\n" - for hourly in daily: - if hourly.time.hour > 7 and hourly.time.hour < 19: - theweather+= " "+hourly.time.strftime("%I:%M %p")+" "+hourly.description+", "+str(hourly.temperature)+" F\n" - elif daily.date == datetime.datetime.today().date()+datetime.timedelta(days=1): - theweather += "Forecast for tomorrow: High: "+str(daily.highest_temperature)+" F, Low: "+str(daily.lowest_temperature)+" F\n" - - return theweather - -if __name__ == '__main__': - theweather = asyncio.run(getweather()) - print(theweather) - diff --git a/imagegen.py b/imagegen.py index 7cf73b6..65a9142 100644 --- a/imagegen.py +++ b/imagegen.py @@ -3,6 +3,7 @@ import datetime import pytz import asyncio import google_weather +import mlb #from getweather import getweather # create an image out = Image.new("L", (800, 480),255) @@ -25,8 +26,8 @@ txt2 = " Current: "+weather["current"] \ +"\n Today's forecast: "+weather["forecast_today"] \ +"\n Tomorrow: "+weather["forecast_tomorrow"] d.multiline_text((1, 60), txt2, font=fnt, fill=0) -d.multiline_text((1, 135), "-----", font=fnt, fill=0) - +d.multiline_text((1, 135), "Pirates:", font=fnt, fill=0) +d.multiline_text((3,160), mlb.get_pirates(), font=fnt, fill=0) out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG") #out.show() diff --git a/mlb.py b/mlb.py new file mode 100644 index 0000000..91095a0 --- /dev/null +++ b/mlb.py @@ -0,0 +1,29 @@ +import statsapi +import datetime + + +def get_pirates(): + results = "" + todaystr = datetime.datetime.now().strftime("%Y-%m-%d") + tomorrow = datetime.datetime.now()+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 += todaysgame[0]["summary"]+" "+todaysgame[0]["game_datetime"]+"\n" + 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" + return results + +if __name__ == '__main__': + print(get_pirates()) + +#print(statsapi.schedule(team=piratesid)) +# 6/5 Local time 7:15 pm '2026-06-05T23:15:00Z' +# 6/6 Local time 4:10 pm '2026-06-06T20:10:00Z' +# 6/7 Local time 1:35 pm '2026-06-07T17:35:00Z' +# datetime.datetime.strptime(game[0]["game_datetime"],"%Y-%m-%dT%H:%M:%SZ") +# gamedateutc = gamedate.replace(tzinfo=datetime.timezone.utc) +# gamedateutc.astimezone() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..47b7b96 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +mlb-statsapi==1.9.0 +pillow==12.2.0 +pytz==2026.2 +requests==2.34.2