eulaurarien/feed_dns.py

45 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import database
import argparse
import sys
FUNCTION_MAP = {
b'a': database.feed_a,
b'cname': database.feed_cname,
}
if __name__ == '__main__':
# Parsing arguments
parser = argparse.ArgumentParser(
description="TODO")
parser.add_argument(
'-i', '--input', type=argparse.FileType('rb'), default=sys.stdin.buffer,
help="TODO")
args = parser.parse_args()
database.open_db()
try:
database.time_step('iowait')
line: bytes
for line in args.input:
database.time_step('feed_json_parse')
split = line.split(b'"')
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()