diff --git a/data/compile.py b/data/compile.py index 540eb6ac8..f01233798 100644 --- a/data/compile.py +++ b/data/compile.py @@ -4,6 +4,7 @@ import processors.areatree.process as areatree import processors.maps.process as maps from processors import ( + aliases, coords, export, images, @@ -115,6 +116,9 @@ def main() -> None: logging.info("-- 97 Search: Get combined ranking") search.add_ranking_combined(data) + logging.info("-- 98 Aliases: extract aliases") + aliases.add_aliases(data) + logging.info("-- 100 Export and generate Sitemap") # the root entry is somewhat arbitrary # leaving it here and thus having it delivered by the other apis leads to bad ergonomics diff --git a/data/processors/aliases.py b/data/processors/aliases.py new file mode 100644 index 000000000..50ee8dc6c --- /dev/null +++ b/data/processors/aliases.py @@ -0,0 +1,18 @@ +from typing import Any + + + +def extract_arch_name(entry: dict) -> str | None: + """Extract the arch name from the entry""" + if entry["type"] == "building": + return f"@{entry['id']}" + return entry.get("tumonline_data", {}).get("arch_name", None) + +def add_aliases(data: dict[str, dict[str, Any]]) -> None: + """Add coordinates to all entries and check for issues""" + + for _id, entry in data.items(): + entry["aliases"] = [] + if arch_name := extract_arch_name(entry): + entry["arch_name"] = arch_name, + entry["aliases"].append(arch_name) \ No newline at end of file diff --git a/data/processors/export.py b/data/processors/export.py index 29df33a62..b3df4cd4c 100644 --- a/data/processors/export.py +++ b/data/processors/export.py @@ -76,7 +76,7 @@ def export_for_search(data: dict) -> None: "ms_id": _id.replace(".", "-"), "id": _id, # not searchable "name": entry["name"], - "arch_name": extract_arch_name(entry), + "arch_name": entry.get("arch_name"), "type": entry["type"], "type_common_name": entry["type_common_name"], "facet": { @@ -118,13 +118,6 @@ def extract_parent_building_names(data: dict, parents: list[str], building_paren return short_names + long_names -def extract_arch_name(entry: dict) -> str | None: - """Extract the arch name from the entry""" - if entry["type"] == "building": - return f"@{entry['id']}" - return entry.get("tumonline_data", {}).get("arch_name", None) - - def _make_sure_is_safe(obj: object): """ Check if any of the specified names in removed_names are present @@ -174,11 +167,6 @@ def export_for_api(data: dict) -> None: export_data = [] for _id, entry in data.items(): entry.setdefault("maps", {})["default"] = "interactive" - - entry["aliases"] = [] - if arch_name := extract_arch_name(entry): - entry["aliases"].append(arch_name) - export_data.append(extract_exported_item(data, entry)) _make_sure_is_safe(export_data)