mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
52
tools/python/mwm/find_feature.py
Executable file
52
tools/python/mwm/find_feature.py
Executable file
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
from typing import List
|
||||
|
||||
from mwm import EnumAsStrEncoder
|
||||
from mwm import Feature
|
||||
from mwm import Mwm
|
||||
from mwm import readable_type
|
||||
|
||||
|
||||
def find_features(path: str, typ: str, string: str) -> List[Feature]:
|
||||
features = []
|
||||
index = int(string) if typ == "id" else None
|
||||
for feature in Mwm(path):
|
||||
found = False
|
||||
if typ == "n":
|
||||
for value in feature.names().values():
|
||||
if string in value:
|
||||
found = True
|
||||
break
|
||||
elif typ in ("t", "et"):
|
||||
for t in feature.types():
|
||||
readable_type_ = readable_type(t)
|
||||
if readable_type_ == string:
|
||||
found = True
|
||||
break
|
||||
elif typ == "t" and string in readable_type_:
|
||||
found = True
|
||||
break
|
||||
elif typ == "m":
|
||||
for f in feature.metadata():
|
||||
if string in f.name:
|
||||
found = True
|
||||
break
|
||||
elif typ == "id" and index == feature.index():
|
||||
found = True
|
||||
|
||||
if found:
|
||||
features.append(feature)
|
||||
|
||||
return features
|
||||
|
||||
|
||||
def find_and_print_features(path: str, typ: str, string: str):
|
||||
for feature in find_features(path, typ, string):
|
||||
print(
|
||||
json.dumps(
|
||||
feature.to_json(),
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
cls=EnumAsStrEncoder,
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user