Parcourir la source

Add script to fetch places from overpass api and put them in firestore

Marcin Jaborski il y a 3 ans
Parent
commit
230156acc4
3 fichiers modifiés avec 94 ajouts et 0 suppressions
  1. 40 0
      fetch_places.py
  2. 42 0
      map features.txt
  3. 12 0
      physigo-firebase-adminsdk-uneji-b592d0d14b.json

+ 40 - 0
fetch_places.py

@@ -0,0 +1,40 @@
+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]}")

+ 42 - 0
map features.txt

@@ -0,0 +1,42 @@
+#amenity=cafe
+#amenity=restaurant
+#amenity=college
+#amenity=library
+#amenity=university
+#amenity=arts_centre
+#amenity=community_centre
+amenity=fountain
+#amenity=planetarium
+#amenity=public_bookcase
+#amenity=social_centre
+#amenity=theatre
+#amenity=townhall
+#amenity=bbq
+#amenity=clock
+boundary=forest
+#building=cathedral
+#building=chapel
+#building=church
+#building=monasery
+#building=mosque
+#building=religious
+#building=shrine
+#building=stadium
+#building=castle
+#building=ruins
+#historic=aircraft
+#historic=aqueduct
+#historic=church
+#historic=memorial
+#historic=monument
+#historic=ruins
+#leisure=dog_park
+leisure=park
+#tourism=artwork
+tourism=attraction
+#tourism=gallery
+#tourism=museum
+tourism=picnic_site
+#tourism=theme_park
+tourism=view_point
+#tourism=zoo

+ 12 - 0
physigo-firebase-adminsdk-uneji-b592d0d14b.json

@@ -0,0 +1,12 @@
+{
+  "type": "service_account",
+  "project_id": "physigo",
+  "private_key_id": "b592d0d14b4268a9ffde5c5d1bd79c5e565d4a83",
+  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCPLVOI7Qwf4vjL\nQtLUSDBb0A9xBkpaQWpJpUIDxh/aUu50hDicNRd4hLa4m0yW9TOOmr6BbRCHED8Y\nUClzdeHVLFnO1G6ydIT+I976+CCKVxarYlYaI5YL+0Ta7zN7S+iLjGq/G1hi8oNi\nOr6GkMHisIlPm8IuC+GDlH9kcdxbZB20x6oPl+K3ZA+7hNMDH0YweaqImc8yQs2l\nc/79ra9dsVzlM36/YpCv52GxMjlzMsKQtDntArmxE6OJLu+9zGsdA453geUhOx5d\nIEQEgvTYpPZFVl28CvM+k7wlz5z5A2Xs7LbutHq9FVVGHOs63t/1VXO6BTahhoZ1\nKzhSP6aHAgMBAAECggEAEwOSoQ/UmQohaYzu8WDCMKSJiG8CF3Ox089DMbvGpc3M\nUQ5GHlMxUhX91gz5t4p0qwQt4djuuvZotVKKpAS3AFeqzZGJ6d/DfE9Ii3fBiohU\n6wmyJDfZngRjzoIPCi64gTUdRVKHrbbwb8PGuEQnxh0U/yImQCCKda5A2has4Y36\nm/0Ed/e1eU99wPVyDYWW/J4PXDw/PdTS8yux5+bLTqy5U0rpg6YlCjRAPk1cjcLL\nkp1neCcenVjYto/NZcA2KV4gRqeh1WPuY3bYuVDZa4ZoOIOp5rGIAI7biSWpnhnB\n4fBObnLd/bjeoOVhRu7BDt146aSTl4Xx/wMVpxQNAQKBgQDB007Z+CI4pI+4m4sM\nWL0mQxgs1TW4SBeHwG8HOhQor1dukMQBNF6G9n7mFkJCm1ax+Z99w4LwETkRMyCb\nMsA4rnr5bByDnT+YB7TxyfY42J/1KY5wBE6wKdJ618fZ5up7q378urufTYJHNISO\nGyKSuAmvgwjXvxsc/o2Ceb7UwQKBgQC9GtcZyzaY9r120eoyMcHSrhIX62gk+OnQ\nTCpKvjnMBAYKzVb5fy6H4WmWYBTsGn3hkI/C9cCc9dFBYvafrgDEb4t0pYIxOhTx\n6KEksOeaH6yS23c5UiLviupGbDaMCMMV4C4pnucjEjBj2M5m62Cv576Q7FQWDWq4\nXOBc0ILlRwKBgQCNFBcyxE90VyNdRaoCBJ04umFgUJhXV/H4l3K5GecObgH/slNY\nZRvgtI5NPypffN2vkXgrfCFUR9T31fUHwfrzxtwvrCddDRn6uLFVxKD5Y4OaWPMa\nSahUxTw0udb3ngJSndNCdVCXdT08Qtew78NMc7RpEcFf9/PuOMIblC34gQKBgDxQ\nnkDc3vok4MNQKrl9w0tWN/EnJV19gt3sHSUfzUF0GxVA7ze+x/GRBONwm9u+i13x\nhNjzF0843FhVn0HI9veweDNpQsA+vUV3JEaWohg3eAyTMVC4EOqETTrO8wrxFIAa\ns76UrzYxa/u8wAB1nK4eZVrF9f/eoaZSAUG5Q7arAoGAMC5BDj8BpHBfKhSRSQ8v\n1/Wz989fuaL8kZcRLrWRLPxN0Gi3pdxxN6NJz/zZDunV8qWdOVr6TOY745lrZtgo\nF0J0qok6X2hfK5I9YyH3jc6T5JdJl6u68kpRmejJUrwIzx21YgA1gWzBgZOQ0vA0\n95KVwn7Q9vQaPBQIrF3e3oI=\n-----END PRIVATE KEY-----\n",
+  "client_email": "firebase-adminsdk-uneji@physigo.iam.gserviceaccount.com",
+  "client_id": "100855566573985137385",
+  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
+  "token_uri": "https://oauth2.googleapis.com/token",
+  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
+  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-uneji%40physigo.iam.gserviceaccount.com"
+}