-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinflux.py
More file actions
42 lines (37 loc) · 1.1 KB
/
influx.py
File metadata and controls
42 lines (37 loc) · 1.1 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
from influxdb import InfluxDBClient
class InfluxWrapper:
def __init__(self,
db,
host,
port,
user,
password):
self.db = db
self.host = host
self.port = port
self.user = user
self.password = password
def write_influx(self, key, value):
formatted_data = [{
"measurement": key,
"tags": {
"sensor": key
},
"fields": {
"value": value
}
}]
conn = InfluxDBClient(self.host,
self.port,
self.user,
self.password,
self.db)
conn.write_points(formatted_data)
def read_influxdb(self, query):
conn = InfluxDBClient(self.host,
self.port,
self.user,
self.password,
self.db)
result = conn.query(query)
return result