While I'm automating this you'll need to download the A set from https://opendata.rapid7.com/sonar.fdns_v2/ to the file a.json.gz.
44 lines
1.1 KiB
Python
Executable file
44 lines
1.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import database
|
|
import argparse
|
|
import sys
|
|
|
|
FUNCTION_MAP = {
|
|
'a': database.feed_a,
|
|
'cname': database.feed_cname,
|
|
}
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Parsing arguments
|
|
parser = argparse.ArgumentParser(
|
|
description="TODO")
|
|
parser.add_argument(
|
|
'-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
|
|
help="TODO")
|
|
args = parser.parse_args()
|
|
|
|
database.open_db()
|
|
|
|
try:
|
|
database.time_step('iowait')
|
|
for line in args.input:
|
|
database.time_step('feed_json_parse')
|
|
split = line.split('"')
|
|
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()
|