summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-08-13 08:41:55 +0200
committerYuval Adam <_@yuv.al>2024-08-13 08:41:55 +0200
commitd12d5b93c22722c063f462c02e1fc4bcbb2e66c7 (patch)
tree741f226bb28a82fb109be1d5b129716adf1723db
parent42d9a7ba14f35c22094dc6545de22dce83afa838 (diff)
Run ruff formatting
-rw-r--r--pakarlib/build.py55
1 files changed, 32 insertions, 23 deletions
diff --git a/pakarlib/build.py b/pakarlib/build.py
index ca685e3..d2e6957 100644
--- a/pakarlib/build.py
+++ b/pakarlib/build.py
@@ -6,56 +6,63 @@ from pathlib import Path
DATA_DIR = Path(__file__).parent / "data"
+
def build_cities():
print("Building cities...")
LANGS = ["he", "ar", "en", "ru"]
LANG_FIELDS = ["label", "mixname", "rashut"]
d = defaultdict(dict)
- lds = defaultdict(lambda: defaultdict(lambda: defaultdict(dict))) # defaultdicts all the way down!
+ lds = defaultdict(
+ lambda: defaultdict(lambda: defaultdict(dict))
+ ) # defaultdicts all the way down!
for lang in LANGS:
- with open(DATA_DIR / "cities"/ f"{lang}.json", "r") as f:
+ with open(DATA_DIR / "cities" / f"{lang}.json", "r") as f:
cities = json.load(f)
for city in cities:
val = city["value"]
for field in LANG_FIELDS:
lds[val][field][lang] = city.pop(field)
d[val].update(city)
-
+
# backfill all lang fields
for k, v in lds.items():
d[k].update(v)
d[k].pop("label_he") # remove the default label_he
- with open(DATA_DIR / "build"/ "cities.json", "w") as f:
+ with open(DATA_DIR / "build" / "cities.json", "w") as f:
f.write(json.dumps(list(d.values())))
+
def build_districts():
print("Building districts...")
LANGS = ["he", "ar", "en", "ru"]
LANG_FIELDS = ["label", "areaname"]
d = defaultdict(dict)
- lds = defaultdict(lambda: defaultdict(lambda: defaultdict(dict))) # defaultdicts all the way down!
+ lds = defaultdict(
+ lambda: defaultdict(lambda: defaultdict(dict))
+ ) # defaultdicts all the way down!
for lang in LANGS:
- with open(DATA_DIR / "districts"/ f"{lang}.json", "r") as f:
+ with open(DATA_DIR / "districts" / f"{lang}.json", "r") as f:
districts = json.load(f)
for district in districts:
val = district["value"]
for field in LANG_FIELDS:
lds[val][field][lang] = district.pop(field)
d[val].update(district)
-
+
# backfill all lang fields
for k, v in lds.items():
d[k].update(v)
d[k].pop("label_he") # remove the default label_he
-
- with open(DATA_DIR / "build"/ "districts.json", "w") as f:
+
+ with open(DATA_DIR / "build" / "districts.json", "w") as f:
f.write(json.dumps(list(d.values())))
+
def build_geojson():
with open(DATA_DIR / "segments" / "he.json", "r") as f:
segments_he = json.load(f)["segments"]
@@ -70,22 +77,23 @@ def build_geojson():
j = json.load(f)
try:
sid = j["segmentId"]
- pgs = [[[b,a] for a,b in j["polygonPointList"][0]]]
+ pgs = [[[b, a] for a, b in j["polygonPointList"][0]]]
od = {
"type": "FeatureCollection",
- "features": [{
- "type": "Feature",
- "properties": {
- "id": sid,
- "hebName": segments_he.get(sid, {}).get("name", ""),
- "engName": segments_en.get(sid, {}).get("name", ""),
- "seconds": int(segments_he.get(sid, {}).get("szSeconds", 0))
- },
- "geometry": {
- "type": "Polygon",
- "coordinates": pgs
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {
+ "id": sid,
+ "hebName": segments_he.get(sid, {}).get("name", ""),
+ "engName": segments_en.get(sid, {}).get("name", ""),
+ "seconds": int(
+ segments_he.get(sid, {}).get("szSeconds", 0)
+ ),
+ },
+ "geometry": {"type": "Polygon", "coordinates": pgs},
}
- }]
+ ],
}
# can save od here if we like
@@ -94,10 +102,11 @@ def build_geojson():
res["features"].append(ft)
except Exception:
pass
-
+
with open(DATA_DIR / "build" / "all.geojson", "w") as out:
json.dump(res, out)
+
def run():
build_cities()
build_districts()