Skip to content

Instantly share code, notes, and snippets.

@dsalaj
Last active January 22, 2019 08:26
Show Gist options
  • Save dsalaj/a692a0ff5fde640d193e4614b6028962 to your computer and use it in GitHub Desktop.
Save dsalaj/a692a0ff5fde640d193e4614b6028962 to your computer and use it in GitHub Desktop.
Traverse directory for json files with results and print some value from dict
import json
import sys
import os
folders = []
files = []
RESULT_KEY = 'test_per'
data = {
'subdir1': [],
'subdir2': [],
}
assert len(sys.argv) == 2
for subdir, dirs, files in os.walk(sys.argv[1]):
for f in files:
if "results.json" in f:
fpath = os.path.join(subdir, f)
d = json.load(open(fpath))
try:
# print(subdir, d['test_per'])
for key in data.keys():
if key in subdir:
data[key].append(d[RESULT_KEY][0])
except:
print(subdir, "ERROR")
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment