-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
25 lines (23 loc) · 1.08 KB
/
helpers.py
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
# Conver processing code to function
def process_results(data):
nested_values = ['video', 'author', 'music', 'stats', 'authorStats', 'challenges', 'duetInfo', 'textExtra', 'stickersOnItem']
skip_values = ['challenges', 'duetInfo', 'textExtra', 'stickersOnItem']
# Create blank dictionary
flattened_data = {}
# Loop through each video
for idx, value in enumerate(data):
flattened_data[idx] = {}
# Loop through each property in each video
for prop_idx, prop_value in value.items():
# Check if nested
if prop_idx in nested_values:
if prop_idx in skip_values:
pass
else:
# Loop through each nested property
for nested_idx, nested_value in prop_value.items():
flattened_data[idx][prop_idx+'_'+nested_idx] = nested_value
# If it's not nested, add it back to the flattened dictionary
else:
flattened_data[idx][prop_idx] = prop_value
return flattened_data