|
|
@@ -0,0 +1,41 @@
|
|
|
+import requests
|
|
|
+import json
|
|
|
+from google.cloud import firestore
|
|
|
+
|
|
|
+import os
|
|
|
+os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "physigo-firebase-adminsdk-uneji-b592d0d14b.json"
|
|
|
+
|
|
|
+db = firestore.Client()
|
|
|
+batch = db.batch()
|
|
|
+
|
|
|
+overpass_url = "https://overpass-api.de/api/interpreter"
|
|
|
+
|
|
|
+with open('map features.txt', 'r') as f:
|
|
|
+ for line in f:
|
|
|
+ if line[0] == "#":
|
|
|
+ continue
|
|
|
+ overpass_query = f"""
|
|
|
+[out:json];
|
|
|
+area["ISO3166-1"="PL"][admin_level=2];
|
|
|
+node[{line[:-1]}](area);
|
|
|
+out center;
|
|
|
+"""
|
|
|
+ response = requests.get(overpass_url, params={"data": overpass_query})
|
|
|
+ try:
|
|
|
+ elements = response.json()["elements"]
|
|
|
+ except json.JSONDecodeError:
|
|
|
+ print(f"Could not decode data for {line[:-1]}")
|
|
|
+ continue
|
|
|
+ object_type = line.split("=")[1].strip()
|
|
|
+ data = {}
|
|
|
+ for el in elements:
|
|
|
+ try:
|
|
|
+ data["name"] = el["tags"].get("name", object_type)
|
|
|
+ data["location"] = firestore.GeoPoint(el["lat"], el["lon"])
|
|
|
+ data["category"] = object_type
|
|
|
+ batch.set(db.collection("Places").document(str(el["id"])), data)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ continue
|
|
|
+ batch.commit()
|
|
|
+ print(f"Finished adding {line[:-1]}")
|