-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert2influxdb.py
27 lines (24 loc) · 1.05 KB
/
convert2influxdb.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
import datetime
import sys
from dateutil.parser import parse
import csv
epoch = datetime.datetime(1970,1,1)
reader = csv.reader(sys.stdin, delimiter=',', quotechar='"')
for row in reader:
# Skip headers
if len(row) > 1 and 'usage' in row[0]:
if 'gas' in row[0]:
# Gas is daily
b = parse(row[1])
timestamp = int((b - epoch).total_seconds() * 1000000000)
print "energy,energy_type=gas,value_type=usage value=%s %s" % (row[2], timestamp)
if row[4][1:] != "":
print "energy,energy_type=gas,value_type=cost value=%s %s" % (row[4][1:], timestamp)
else:
# Electricity is hourly
b = parse("%s %s" % (row[1], row[2]))
timestamp = int((b - epoch).total_seconds() * 1000000000)
print "energy,energy_type=electric,value_type=usage value=%s %s" % (row[4], timestamp)
if row[6][1:] != "":
print "energy,energy_type=electric,value_type=cost value=%s %s" % (row[6][1:], timestamp)
# print ', '.join(row)