2019-12-09 08:12:48 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import database
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
FUNCTION_MAP = {
|
2019-12-09 08:55:34 +01:00
|
|
|
b'a': database.feed_a,
|
|
|
|
b'cname': database.feed_cname,
|
2019-12-09 08:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Parsing arguments
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="TODO")
|
|
|
|
parser.add_argument(
|
2019-12-09 08:55:34 +01:00
|
|
|
'-i', '--input', type=argparse.FileType('rb'), default=sys.stdin.buffer,
|
2019-12-09 08:12:48 +01:00
|
|
|
help="TODO")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
database.open_db()
|
|
|
|
|
|
|
|
try:
|
|
|
|
database.time_step('iowait')
|
2019-12-09 08:55:34 +01:00
|
|
|
line: bytes
|
2019-12-09 08:12:48 +01:00
|
|
|
for line in args.input:
|
|
|
|
database.time_step('feed_json_parse')
|
2019-12-09 08:55:34 +01:00
|
|
|
split = line.split(b'"')
|
2019-12-09 08:12:48 +01:00
|
|
|
name = split[7]
|
|
|
|
dtype = split[11]
|
|
|
|
value = split[15]
|
|
|
|
# data = json.loads(line)
|
|
|
|
# assert dtype == data['type']
|
|
|
|
# assert name == data['name']
|
|
|
|
# assert value == data['value']
|
|
|
|
database.time_step('feed_switch')
|
|
|
|
FUNCTION_MAP[dtype](name, value)
|
|
|
|
database.time_step('iowait')
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("Interupted.")
|
|
|
|
pass
|
|
|
|
|
|
|
|
database.close_db()
|