|
|
@@ -1,40 +0,0 @@
|
|
|
-import requests
|
|
|
-import json
|
|
|
-import uuid
|
|
|
-from google.cloud import firestore
|
|
|
-
|
|
|
-import os
|
|
|
-os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "physigo-firebase-adminsdk-uneji-b592d0d14b.json"
|
|
|
-
|
|
|
-db = firestore.Client()
|
|
|
-
|
|
|
-overpass_url = "http://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
|
|
|
- db.collection("Places").document(str(el["id"])).set(data)
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- continue
|
|
|
- print(f"Finished adding {line[:-1]}")
|