Marcin Jaborski 3 лет назад
Родитель
Сommit
5658e137e6
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      scripts/fetch_places.py

+ 6 - 0
scripts/fetch_places.py

@@ -7,6 +7,7 @@ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "physigo-firebase-adminsdk-uneji-
 
 db = firestore.Client()
 batch = db.batch()
+count = 0
 
 overpass_url = "https://overpass-api.de/api/interpreter"
 
@@ -34,8 +35,13 @@ out center;
                 data["location"] = firestore.GeoPoint(el["lat"], el["lon"])
                 data["category"] = object_type
                 batch.set(db.collection("Places").document(str(el["id"])), data)
+                count += 1
+                if count == 500:
+                    count = 0
+                    batch.commit()
             except Exception as e:
                 print(e)
                 continue
         batch.commit()
+        count = 0
         print(f"Finished adding {line[:-1]}")