-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (24 loc) · 1.1 KB
/
utils.py
File metadata and controls
30 lines (24 loc) · 1.1 KB
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
29
30
import copy
import json
def save_json_to_file(fileName, data):
with open(fileName, 'w') as f:
f.write(json.dumps(data, indent=4))
def filter_by_open(data):
# create a deep copy of data to prevent a change in the objects size during iteration
data_open_spots = copy.deepcopy(data)
# iterate over the data and remove all of the positions with 0 available spots
for (key_fair, fair) in data.items():
print(key_fair)
for (key_company, company) in fair.items():
print(key_company)
if (isinstance(company, str)):
del data_open_spots[key_fair][key_company]
continue
for (key_position, position) in company.items():
print(key_position)
if (position['Spots Open'] == 0):
del data_open_spots[key_fair][key_company][key_position]
# remove the companies with empty directories (no positions)
for (key_fair, fair) in data_open_spots.items():
data_open_spots[key_fair] = {i:j for i,j in fair.items() if j != {}}
return data_open_spots