Skip to content

Instantly share code, notes, and snippets.

@nagos
Created February 5, 2020 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagos/236d66d8c3bd5897a30b4675b5bed497 to your computer and use it in GitHub Desktop.
Save nagos/236d66d8c3bd5897a30b4675b5bed497 to your computer and use it in GitHub Desktop.
Python to InfluxDB transfer
#!/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