Created
June 2, 2015 05:03
-
-
Save lanfon72/af4434b38ecb67e32bc9 to your computer and use it in GitHub Desktop.
insert influx data.
This file contains hidden or 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 python | |
| #coding:utf8 | |
| from datetime import datetime | |
| from influxdb import InfluxDBClient | |
| import fileinput | |
| import ast | |
| client = InfluxDBClient("localhost", 8086, 'guest', 'guest', 'twER') | |
| files = open('temp').read().splitlines() | |
| points =[] | |
| columns = ['pending_bed', 'pending_icu', 'hospital_sn', 'full_reported', 'time', 'pending_doctor', 'pending_ward'] | |
| for line in fileinput.input(files): | |
| line = line.replace('false', 'False').replace('true',"True").replace('update_time','time').rstrip('\n') | |
| try: | |
| line = ast.literal_eval(line) | |
| if isinstance(line['time'], str) and "null" in line['time']: | |
| f_time = fileinput.filename()[:-1] + "0" | |
| line['time'] = datetime.strptime(f_time, "%Y-%m-%d_%H-%M").strftime("%s") | |
| line['time'] = int(line['time']) | |
| points.append( [line[col] for col in columns] ) | |
| except StandardError as e: | |
| print "{0} pass line, error: {1}".format(line, e) | |
| json_body = [{"points":points, "name":'ER', "columns":columns}] | |
| print len(points) | |
| print client.write_points(json_body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment