Last active
December 22, 2015 05:58
-
-
Save kf0jvt/6427704 to your computer and use it in GitHub Desktop.
We noticed a problem with the VERIS Community Database where incidents that involved loss or theft were not being coded up with the availability attribute set. This script fixes that for all those incidents. #VCDB
This file contains 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 json | |
import os | |
def FixAttribute(inDict,filename): | |
if 'availability' not in inDict['attribute'].keys(): | |
print filename + " is messed up." | |
inDict['attribute']['availability'] = {} | |
inDict['attribute']['availability']['variety'] = ['Loss'] | |
return inDict | |
print "Starting" | |
for (path, dirs, files) in os.walk('.'): | |
for filename in files: | |
incident = json.loads(open(filename).read()) | |
if 'physical' in incident['action'].keys(): | |
if 'Theft' in incident['action']['physical']['variety']: | |
incident = FixAttribute(incident,filename) | |
outfile = open(filename,'w') | |
outfile.write(json.dumps(incident,indent=2, sort_keys=True,separators=(',', ': '))) | |
outfile.close() | |
if 'error' in incident['action'].keys(): | |
if 'Loss' in incident['action']['error']['variety']: | |
incident = FixAttribute(incident,filename) | |
outfile = open(filename,'w') | |
outfile.write(json.dumps(incident,indent=2, sort_keys=True, separators=(',', ': '))) | |
outfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment