forked from null8626/python-weather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
29 lines (22 loc) · 911 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# import the module
import python_weather
import asyncio
import os
async def getweather():
# declare the client. format defaults to the metric system (celcius, km/h, etc.)
client = python_weather.Client(format=python_weather.IMPERIAL)
# fetch a weather forecast from a city
weather = await client.find("Calgery Alberta")
# returns the current day's forecast temperature (int)
print(weather.current.temperature)
# get the weather forecast for a few days
for forecast in weather.forecasts:
print(str(forecast.date), forecast.sky_text, forecast.temperature)
# close the wrapper once done
await client.close()
if __name__ == "__main__":
# see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
# for more details
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(getweather())