-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaqi.py
executable file
·41 lines (33 loc) · 1.04 KB
/
aqi.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
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import settings
import logging
from influxdb import InfluxDBClient
from data_source import openweathermap, airnow, purpleair
purpleair_sensors = settings.PURPLEAIR_SENSORS.split(",")
points = []
# Get weather
try:
points += openweathermap.get_points(settings.POSTCODE)
except Exception as error:
logging.warning("fail to get weather data: %s", error)
# Get Air Quality Index
try:
points += airnow.get_points(settings.POSTCODE)
except Exception as error:
logging.warning("fail to get Air Quality data: %s", error)
# Get Air Quality Index from purple air
try:
for sensor in purpleair_sensors:
points += purpleair.get_points(sensor)
except Exception as error:
logging.warning("fail to get Purple Air data: %s", error)
influx = InfluxDBClient(
settings.INFLUXDB["URL"],
settings.INFLUXDB["PORT"],
settings.INFLUXDB["USER"],
settings.INFLUXDB["PASSWORD"],
settings.INFLUXDB["DB"],
ssl=settings.INFLUXDB["SSL"],
verify_ssl=settings.INFLUXDB["SSL"],
)
influx.write_points(points)