-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.py
36 lines (30 loc) · 1.3 KB
/
import.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
from influxdb import InfluxDBClient
import fire
from csv import reader
def main(ketonix_filename='ketonix_username.csv', influx_host='localhost', influx_port=8086, inlux_user='root', influx_password='root', influx_dbname='health'):
"""Parse a ketonix.com csv ketones measureents results into a InfluxDB."""
client = InfluxDBClient(influx_host, influx_port, influx_user, influx_password, influx_dbname)
with open(ketonix_filename, 'r') as read_obj:
csv_reader = reader(read_obj, delimiter=';')
measurement_date=""
measurement=0
for row in csv_reader:
# row variable is a list that represents a row in csv
measurement_date=row[0]+"T"+row[1]+"Z"
measurement_name=row[2]
measurement=row[3]
json_body = [
{
"measurement": "Ketonix_" + measurement_name,
"time": measurement_date,
"fields": {
"Float_value": float(measurement),
"String_value": measurement_name,
"Bool_value": True
}
}
]
print("Write points: {0}".format(json_body))
client.write_points(json_body)
if __name__ == '__main__':
fire.Fire(main)