aboutsummaryrefslogtreecommitdiffstats
path: root/src/osm_where.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/osm_where.py')
-rwxr-xr-xsrc/osm_where.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/osm_where.py b/src/osm_where.py
new file mode 100755
index 0000000..e0b7022
--- /dev/null
+++ b/src/osm_where.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+import argparse
+from OSMPythonTools.overpass import Overpass
+
+import logging
+
+logging.getLogger("OSMPythonTools").setLevel(logging.ERROR)
+
+
+def get_URI(name, area, lang):
+ overpass = Overpass()
+
+ result = overpass.query(
+ f'area["ISO3166-1"="{area}"][admin_level=2];relation["name:{lang}"="{name}"](area);out center;'
+ )
+ if len(result.elements()) > 0:
+ bakhmut = result.elements()[0]
+ return bakhmut.centerLat(), bakhmut.centerLon()
+ else:
+ return None
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ prog="osm_where", description="Get geo: URI for given locality from OSM"
+ )
+ parser.add_argument("name")
+ parser.add_argument("-a", "--area", default="UA", help="ISO 3166 area code")
+ parser.add_argument("-l", "--lang", default="en", help="ISO 639-1 language code")
+ args = parser.parse_args()
+
+ geo = get_URI(args.name, args.area, args.lang)
+ if geo:
+ print(f"geo:{geo[0]},{geo[1]}")
+
+
+if __name__ == "__main__":
+ main()