-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_dump.py
26 lines (24 loc) · 993 Bytes
/
db_dump.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
#! /usr/bin/env python3
import json
import pymysql
def dbconnect(sql):
host = "10.68.25.61"
user = "dsm_user"
password = "password"
db = "dsmutils_csv"
con = pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=pymysql.cursors.DictCursor)
cur = con.cursor()
cur.execute(sql)
tables = cur.fetchall()
con.close()
return tables
def log_api(log_table):
db = log_table
sql = "select timestamp, rpm, airflow, fronto2, timing, inttemp, cooltemp, knockret, speed, throtpos from " + db + ";"
dump = dbconnect(sql)
log = []
for i in dump:
time = i['timestamp']
log.append({'time': i['timestamp'], 'rpm': i['rpm'], 'airflow': float(i['airflow']), 'fronto2': float(i['fronto2']), 'timing': float(i['timing']), 'inttemp': float(i['inttemp']), 'cooltemp': float(i['cooltemp']), 'knockret': float(i['knockret']), 'speed': float(i['speed']), 'throtpos': float(i['throtpos'])})
jlog = json.dumps(log, indent=4)
return jlog