Last active
January 22, 2019 08:26
-
-
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
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 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