#!/usr/bin/python3
import sys
import json

def file_save(file_name, text_to_save):
	with open(file_name, "w") as sysfile:
		sysfile.write(text_to_save)
	sysfile.close

data = open(sys.argv[1]).read().replace('\n','')
jdata = json.loads(data)

for issue in jdata['issues']:
	vuln = {}
	vuln['version'] = 1
	vuln['issues'] = []
	dissue = issue
	for i in dissue['affected_hosts']:
		i['id'] = None
	dissue['id'] = None
	dissue['status'] = 'Draft'
	vuln['issues'].append(dissue)
	file_save(str(str(vuln['issues'][0]['name']).replace(' ', '_').replace('<', '_').replace('/', '_').replace('=', '_'))+ '.json', json.dumps(vuln, indent=4, sort_keys=True))
