import json
import sys

input_dir="/usr/src/app/vmp/malwaredb/virus_total/"
output_dir="/usr/src/app/vmp/malwaredb/templates/"

# [input] parser-json-xml.py file-hash
json_file = open(input_dir+sys.argv[1],"r")
json_data = ""

# read file
for line in json_file:
    json_data += line

# print(json_data)

data = json.loads(json_data)
fh = None
try:
    fh = open(output_dir+sys.argv[1]+"_json.html", "w")
    fh.write('<table style="width:100%">\n')
    for item in data['scans'].items():
        fh.write('<tr>\n')
        fh.write('<td>' + str(item[0]) + '</td>\n')
        for attr_key, attr_value in item[1].items():
            #fh.write('<td>' + str(attr_key) + " " + str(attr_value) + '</td>\n')
            fh.write('<td>' + str(attr_value) + '</td>\n')
        fh.write("</tr>\n")
    fh.write('</table>')
finally:
    if fh != None:
        fh.close()  
