-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_cie_data.py
More file actions
44 lines (32 loc) · 1.14 KB
/
Copy pathsplit_cie_data.py
File metadata and controls
44 lines (32 loc) · 1.14 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import json
import os
def split_cie_data():
input_file = 'public/cie_data.json'
if not os.path.exists(input_file):
print(f"File {input_file} not found.")
return
print(f"Reading {input_file}...")
with open(input_file, 'r') as f:
data = json.load(f)
print(f"Total records: {len(data)}")
# Group by Category
grouped_data = {}
for item in data:
category = item.get('Category')
if not category:
print(f"Warning: Item without category: {item}")
continue
if category not in grouped_data:
grouped_data[category] = []
grouped_data[category].append(item)
# Save to separate files
for category, items in grouped_data.items():
# Create a safe filename
safe_filename = category.replace(' ', '_').replace('&', 'and')
output_file = f'public/cie_{safe_filename}.json'
print(f"Saving {len(items)} records to {output_file}...")
with open(output_file, 'w') as f:
json.dump(items, f)
print("Done.")
if __name__ == "__main__":
split_cie_data()