File: example.py

package info (click to toggle)
python-luftdaten 0.7.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 128 kB
  • sloc: python: 172; makefile: 6; sh: 5
file content (32 lines) | stat: -rw-r--r-- 732 bytes parent folder | download
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
"""Example for getting the data from a station."""
import asyncio

from luftdaten import Luftdaten

SENSOR_ID = 152


async def main():
    """Sample code to retrieve the data."""
    data = Luftdaten(SENSOR_ID)
    await data.get_data()

    if not await data.validate_sensor():
        print("Station is not available:", data.sensor_id)
        return

    if data.values and data.meta:
        # Print the sensor values
        print("Sensor values:", data.values)

        # Print the coordinates fo the sensor
        print(
            "Location:",
            data.meta["latitude"],
            data.meta["longitude"],
            data.meta["altitude"],
        )

        
if __name__ == "__main__":
    asyncio.run(main())