-
Notifications
You must be signed in to change notification settings - Fork 6
/
bulk_tutanak.py
33 lines (22 loc) · 913 Bytes
/
bulk_tutanak.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
26
27
28
29
30
31
32
33
import json
import os
import tutanak
def extract_school_ids(data) -> list[str]:
school_ids = []
for district in data["districts"]:
for neighborhood in district["neighborhoods"]:
for school in neighborhood["schools"]:
school_ids.append(school["id"])
return school_ids
if __name__ == "__main__":
city_json_path = input("Enter city json path: ")
with open(city_json_path, "r", encoding="utf-8") as f:
city_json = json.load(f)
output_path = os.path.join("data", str(city_json["plate"]))
os.makedirs(output_path, exist_ok=True)
schools = extract_school_ids(city_json)
for school in schools:
result = tutanak.send_request(school)
filename = os.path.join(output_path, f"school_{school}.json")
with open(filename, "w", encoding="utf-8") as f:
json.dump(result, f, ensure_ascii=False, indent=4)