-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (24 loc) · 750 Bytes
/
utils.py
File metadata and controls
28 lines (24 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from functools import reduce
import operator
def get_from_dict(dataDict, mapList):
return reduce(operator.getitem, mapList, dataDict)
def dict_to_list(d):
result = {}
for key, value in d.items():
if not isinstance(value, dict):
result[key] = value.pop()
else:
result[key] = dict_to_list(value)
return result
def parse(keys):
def wrapper(func):
def wrapped(*args, **kwargs):
forecast = func(*args, **kwargs)
result = []
if not keys:
return [forecast]
while get_from_dict(forecast, keys):
result = [dict_to_list(forecast)] + result
return result
return wrapped
return wrapper