| import json |
| import os |
|
|
| input_file = "segments.json" |
| output_dir = "test_segments" |
|
|
| print(f"Loading {input_file}...") |
| with open(input_file, "r") as f: |
| data = json.load(f) |
|
|
| surahs = {} |
|
|
| |
| for key, value in data.items(): |
| surah_id, verse_id = key.split(":") |
| surah_num = int(surah_id) |
| |
| surah_str = f"{surah_num:03d}" |
| |
| if surah_str not in surahs: |
| surahs[surah_str] = {} |
| |
| surahs[surah_str][key] = value |
|
|
| |
| os.makedirs(output_dir, exist_ok=True) |
|
|
| |
| for surah_str, surah_data in surahs.items(): |
| output_path = os.path.join(output_dir, f"{surah_str}.json") |
| with open(output_path, "w") as f: |
| |
| json.dump(surah_data, f, separators=(',', ':')) |
|
|
| print(f"Successfully split into {len(surahs)} surah JSON files in '{output_dir}/' folder.") |
|
|