Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into 11-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Aug 8, 2018
2 parents 3409a99 + 40fbe11 commit 7179e91
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions aggregates.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import json
from cove_360.lib.threesixtygiving import get_grants_aggregates

def none_keys_to_str(x):
def replace_none_keys(nested_data):
'''
Walk a dict or list and replace any `None` keys with `'None'`.
Replacement is done in place.
'''
if hasattr(x, 'items'):
for key, value in x.items():
if hasattr(nested_data, 'items'):
for key, value in nested_data.items():
if key is None:
del x[key]
x[str(key)] = value
none_keys_to_str(value)
elif isinstance(x, str):
del nested_data[key]
nested_data[str(key)] = value
replace_none_keys(value)
elif isinstance(nested_data, str):
return
elif hasattr(x, '__iter__'):
for item in x:
none_keys_to_str(item)
elif hasattr(nested_data, '__iter__'):
for item in nested_data:
replace_none_keys(item)

data_all = json.load(open('data/data_all.json'))
stats = []
Expand All @@ -38,7 +38,7 @@ def none_keys_to_str(x):
del aggregates[k]
aggregates = {k:sorted(list(v)) if isinstance(v, set) else v for k,v in aggregates.items()}
dataset['datagetter_aggregates'] = aggregates
none_keys_to_str(dataset)
replace_none_keys(dataset)
stats.append(dataset)
with open('data/status.json', 'w') as fp:
json.dump(stats, fp, indent=' ', sort_keys=True)

0 comments on commit 7179e91

Please sign in to comment.