-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflux.py
36 lines (25 loc) · 947 Bytes
/
influx.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
#!/usr/bin/env python3
import dateutil.parser
from influxdb import InfluxDBClient
class InfluxDb:
def __init__(self, host, port, user, password, dbname, measurement, tags) :
self.measurement = measurement
self.tags = tags
self._influxdb = InfluxDBClient(host, port, user, password, dbname)
def get_last_update(self) :
select = self._influxdb.query('SELECT LAST(power) FROM "pv"')
if len(select) < 1 :
return None
last_update = select.raw['series'][0]['values'][0][0]
return dateutil.parser.isoparse(last_update)
def write(self, points) :
out = []
for date in points :
point = {
"measurement": self.measurement,
"tags": self.tags,
"time": date,
}
point['fields'] = points[date]
out.append(point)
self._influxdb.write_points(out)