Created
February 5, 2020 05:23
-
-
Save nagos/236d66d8c3bd5897a30b4675b5bed497 to your computer and use it in GitHub Desktop.
Python to InfluxDB transfer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
from influxdb import InfluxDBClient | |
def process(fname): | |
with open(fname) as infile: | |
json_body = [] | |
for line in infile: | |
d = line.rstrip().split('\t') | |
if(len(d)==8): | |
(timestamp, BAT_V, BAT_I, button, VIN19V, temp, temp2, code) = [float(x) for x in d] | |
json_body.append( | |
{ | |
"measurement": "data", | |
"time": int(timestamp), | |
"fields": { | |
"BAT_V": BAT_V, | |
"BAT_I": BAT_I, | |
"button": button, | |
"VIN19V": VIN19V, | |
"temp": temp, | |
"temp2": temp2, | |
"code": code, | |
} | |
} | |
) | |
client.write_points(json_body, time_precision='s') | |
if __name__ == "__main__": | |
global client | |
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'mydb') | |
for f in sys.argv[1:]: | |
process(f) | |
print(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment