Skip to content

Instantly share code, notes, and snippets.

@kf0jvt
Created September 24, 2013 04:11
Show Gist options
  • Save kf0jvt/6680278 to your computer and use it in GitHub Desktop.
Save kf0jvt/6680278 to your computer and use it in GitHub Desktop.
Script I wrote to fix a problem that we found in VCDB where a few of the incidents did not have a valid confidentiality attribute. We created new json files, but we couldn't overwrite the old ones because other changes would have been lost. This script maps the reference field to the filename so we can replace just the confidentiality section of…
import os
import json
vcdb_path = 'Documents/development/python/VCDB/incidents'
prc_fix_path = 'Downloads/prc-fix'
mapping = {}
for filename in os.listdir(vcdb_path):
if filename.endswith('.json'):
i = json.loads(open(os.path.join(vcdb_path,filename)).read())
if 'reference' in i.keys():
mapping[i['reference']] = i['incident_id']
for filename in os.listdir(prc_fix_path):
if filename.endswith('.json'):
print "reading file",filename
i = json.loads(open(os.path.join(prc_fix_path,filename)).read())
fix_incident = json.loads(open(os.path.join(vcdb_path,mapping[i['reference']] + '.json')).read())
print "\tFixing file",mapping[i['reference']]
fix_incident['attribute']['confidentiality'] = i['attribute']['confidentiality']
try:
fix_incident['attribute'].pop(' confidentiality')
except:
next
outfile = open(os.path.join(vcdb_path,mapping[i['reference']] + '.json'),'w')
outfile.write(json.dumps(fix_incident,indent=2, sort_keys=True, separators=(',', ': ')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment