Created
September 24, 2013 04:11
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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