-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_rest.py
More file actions
51 lines (37 loc) · 1.51 KB
/
example_rest.py
File metadata and controls
51 lines (37 loc) · 1.51 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import asyncio
import os
from weatherflow4py.api import WeatherFlowRestAPI
from dotenv import load_dotenv
import logging
logging.basicConfig(level=logging.DEBUG)
async def main():
load_dotenv() # load environment variables from .env file
token = os.getenv("TOKEN")
async with WeatherFlowRestAPI(token) as api:
data = await api.get_all_data()
print(data)
while True:
async with WeatherFlowRestAPI(token) as api:
station_response = await api.async_get_stations()
for station in station_response.stations:
print(station.name)
print(station.station_id)
print(station.public_name)
print(station.latitude)
print(station.longitude)
print(station.elevation)
print(station.devices)
print("\n")
forecast = await api.async_get_forecast(station_id=station.station_id)
print(forecast.units)
obs = await api.async_get_observation(station_id=station.station_id)
print(obs.station_id)
print(obs.obs[0].air_temperature)
# obs = await api.async_get_device_observations()
# device_obs = await api.async_get_device_observations(
# station.outdoor_devices[0].device_ids
# )
# print(device_obs.precipitation_type)
await asyncio.sleep(5)
if __name__ == "__main__":
asyncio.run(main())