Files
OpenDisplay/getweather.py
2026-05-24 21:07:04 +00:00

29 lines
1.1 KiB
Python

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)