44 lines
2.2 KiB
Python
44 lines
2.2 KiB
Python
import re
|
|
sqlreg = []
|
|
regFind1 = "INSERT INTO (\w*) [(](\w*),\s(\w*),\s(\w*),\s(\w*),\s(\w*),\s(\w*),\s(\w*)[)] VALUES [(]'(\S*)',\s(\S*),\s'(\S*)',\s'(\S*)',\s(\S*),\s(\S*),\s'(\S*)'[)];"
|
|
regFind2 = "INSERT INTO (\w*) [(](\w*),\s(\w*),\s(\w*),\s(\w*),\s(\w*),\s(\w*)[)] VALUES [(]'(\S*)',\s(\S*),\s'(\S*)',\s'(\S*)',\s(\S*), (\S*)[)];"
|
|
|
|
with open("/Users/patrickjmcd/Henry_Pump/poconsole/datalogger/tagSetup.sql", 'rb') as sqlFile:
|
|
sqlines = sqlFile.readlines()
|
|
|
|
with open('output.txt', 'wb') as outFile:
|
|
for line in sqlines:
|
|
if len(line) > 10:
|
|
# outFile.write line.replace("\n", "")
|
|
t = re.search(regFind1, line.replace("\n", ""))
|
|
if t:
|
|
outFile.write("{\n")
|
|
outFile.write("name: '{}',\n".format(t.group(9)))
|
|
outFile.write("class: {},\n".format(t.group(10)))
|
|
outFile.write("tag: '{}',\n".format(t.group(11)))
|
|
outFile.write("data_type: '{}',\n".format(t.group(12)))
|
|
outFile.write("change_threshold: {},\n".format(t.group(13)))
|
|
outFile.write("guarantee_sec: {},\n".format(t.group(14)))
|
|
outFile.write("map_function: '{}',\n".format(t.group(15)))
|
|
outFile.write("},\n")
|
|
# sqlreg.append(t)
|
|
else:
|
|
t = re.search(regFind2, line.replace("\n", ""))
|
|
# try:
|
|
# i = 0
|
|
# while True:
|
|
# outFile.write("{} - {}".format(i, t.group(i)))
|
|
# i = i + 1
|
|
# except:
|
|
# pass
|
|
if t:
|
|
outFile.write("{\n")
|
|
outFile.write("name: '{}',\n".format(t.group(8)))
|
|
outFile.write("class: {},\n".format(t.group(9)))
|
|
outFile.write("tag: '{}',\n".format(t.group(10)))
|
|
outFile.write("data_type: '{}',\n".format(t.group(11)))
|
|
outFile.write("change_threshold: {},\n".format(t.group(12)))
|
|
outFile.write("guarantee_sec: {},\n".format(t.group(13)))
|
|
outFile.write("},\n")
|
|
# sqlreg.append(t)
|