Tweaking, including reducing sig figs in weather
This commit is contained in:
@@ -70,7 +70,7 @@ def get_google_weather():
|
||||
humidity = current_data.get("relativeHumidity")
|
||||
|
||||
theweather["current"] = (f"{condition}") + (f", {temp.get('degrees')}°F")\
|
||||
+ (f", {humidity}%") + (f" hum., Feels like: {feels_like.get('degrees')}°F")
|
||||
+ (f", {humidity}%") + (f" hum., Feels like: {int(feels_like.get('degrees'))}°F")
|
||||
else: # current_data not returned
|
||||
theweather["current"] = "Problem retrieving current weather"
|
||||
|
||||
@@ -81,12 +81,12 @@ def get_google_weather():
|
||||
max_temp = day.get("maxTemperature", {}).get("degrees")
|
||||
min_temp = day.get("minTemperature", {}).get("degrees")
|
||||
condition = day.get("daytimeForecast", {}).get("weatherCondition", {}).get("description", {}).get("text")
|
||||
theweather["forecast_today"] = (f"{condition}") + (f", {min_temp}°F-{max_temp}°F")
|
||||
theweather["forecast_today"] = (f"{condition}") + (f", {int(min_temp)}°F-{int(max_temp)}°F")
|
||||
day = forecast_data.get("forecastDays", [])[1]
|
||||
max_temp = day.get("maxTemperature", {}).get("degrees")
|
||||
min_temp = day.get("minTemperature", {}).get("degrees")
|
||||
condition = day.get("daytimeForecast", {}).get("weatherCondition", {}).get("description", {}).get("text")
|
||||
theweather["forecast_tomorrow"] = (f"{condition}") + (f", {min_temp}°F-{max_temp}°F")
|
||||
theweather["forecast_tomorrow"] = (f"{condition}") + (f", {int(min_temp)}°F-{int(max_temp)}°F")
|
||||
else:
|
||||
theweather["forecast_tomorrow"] = "Problem retrieving weather forecast"
|
||||
|
||||
|
||||
12
imagegen.py
12
imagegen.py
@@ -20,10 +20,10 @@ row = 0 # current row to write at
|
||||
out = Image.new("L", (displaysize[0], displaysize[1]),255)
|
||||
|
||||
# get a font
|
||||
HeightNormal = 25
|
||||
HeightBold = 35
|
||||
#HeightNormal = 25
|
||||
#HeightBold = 35
|
||||
MarginLeft = 1
|
||||
MarginIndent = 5
|
||||
MarginIndent = 10
|
||||
# get a drawing context
|
||||
d = ImageDraw.Draw(out)
|
||||
|
||||
@@ -35,7 +35,7 @@ row = WriteTextBlock(txt1,d,fntBigBold,displaysize[0]/2,row,"ma")
|
||||
txt1a = "As of "+datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%I:%M %p')
|
||||
row = WriteTextBlock(txt1a,d,fnt,displaysize[0]/2,row,"ma")
|
||||
|
||||
row = WriteTextBlock("Weather",d,fnt,MarginLeft,row,"la")
|
||||
row = WriteTextBlock("Weather",d,fntBold,MarginLeft,row,"la")
|
||||
try:
|
||||
weather = google_weather.get_google_weather()
|
||||
txt2 = "Current: "+weather["current"] \
|
||||
@@ -45,11 +45,9 @@ except: # Assume the weather API blew up
|
||||
txt2 = "Problem getting weather (from ImageGen)"
|
||||
row = WriteTextBlock(txt2,d,fnt,MarginIndent,row,"la")
|
||||
|
||||
row = WriteTextBlock("Pirates",d,fnt,MarginLeft,row,"la")
|
||||
row = WriteTextBlock("Pirates",d,fntBold,MarginLeft,row,"la")
|
||||
row = WriteTextBlock(mlb.get_pirates(),d,fnt,MarginIndent,row,"la")
|
||||
|
||||
row = WriteTextBlock("========== End =========",d,fnt,MarginLeft,row,"la")
|
||||
|
||||
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
|
||||
#out.show()
|
||||
|
||||
|
||||
9
mlb.py
9
mlb.py
@@ -21,8 +21,10 @@ def process_game(game,mytz):
|
||||
else: # game in progress
|
||||
if score_pirates > score_other:
|
||||
results += ", Pirates winning"
|
||||
else:
|
||||
elif score_pirates < score_other:
|
||||
results += ", Pirates losing"
|
||||
else:
|
||||
results += ", tied"
|
||||
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")
|
||||
@@ -45,7 +47,12 @@ def get_pirates():
|
||||
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")
|
||||
yesterday = datetime.datetime.now(tz=useastern_timezone)+datetime.timedelta(days=-1)
|
||||
yesterdaystr = yesterday.strftime("%Y-%m-%d")
|
||||
piratesid = statsapi.lookup_team('pittsburgh')[0]['id']
|
||||
yesterdaysgame = statsapi.schedule(team=piratesid,date=yesterdaystr)
|
||||
if yesterdaysgame:
|
||||
results+= "Yesterday: "+process_game(yesterdaysgame[0],useastern_timezone)+"\n"
|
||||
todaysgame = statsapi.schedule(team=piratesid,date=todaystr)
|
||||
if todaysgame:
|
||||
results+= "Today: "+process_game(todaysgame[0],useastern_timezone)+"\n"
|
||||
|
||||
Reference in New Issue
Block a user