Skip to content

Instantly share code, notes, and snippets.

@tomharris
Created November 7, 2023 03:12
Show Gist options
  • Save tomharris/ed68078a2612fba24757303cee1191be to your computer and use it in GitHub Desktop.
Save tomharris/ed68078a2612fba24757303cee1191be to your computer and use it in GitHub Desktop.
import glob
import json
import os
for f in glob.glob('*/*.json'):
outlist = []
doc = json.load(open(f))
for app in doc:
out_stub = {}
out_stub['title'] = app['title']
assessment = app['assessment']
if assessment is None:
continue
out_stub['publisher'] = assessment['publisherName']
out_stub['platformType'] = assessment['platformType']
for task_type, value in assessment['analysis']['task'].items():
if value is None:
continue
if task_type == 'yaapStatic':
result_location = value['result'][0]
else:
result_location = value['result']
for task, task_output in result_location.items():
out = out_stub.copy()
out['task_type'] = task_type
out['task'] = task
out['data'] = task_output
outlist.append(out)
outfile_tokens = f.split('/')
output_dir = '/'.join(outfile_tokens[:-1]) + '/output/'
if not os.path.exists(output_dir):
os.mkdir(output_dir)
outfilename = output_dir + outfile_tokens[-1]
print(outfilename)
with open(outfilename,'w') as g:
g.write(json.dumps(outlist, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment