First pass at Pirates
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ bin
|
||||
lib
|
||||
lib64
|
||||
__pycache__
|
||||
old
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
29
mlb.py
Normal file
29
mlb.py
Normal file
@@ -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()
|
||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
mlb-statsapi==1.9.0
|
||||
pillow==12.2.0
|
||||
pytz==2026.2
|
||||
requests==2.34.2
|
||||
Reference in New Issue
Block a user