-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddData.py
47 lines (44 loc) · 1.66 KB
/
addData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import glob
cred = credentials.Certificate("look-inside-view-firebase-adminsdk.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
print("choose type: all, one")
type = input()
if type == "all":
files = glob.glob("public/data/*")
for fileName in files:
print(fileName)
if fileName != "public/data\_default.json":
jsonData = json.load(open(fileName, 'r', encoding="utf-8_sig"))
print(jsonData)
db.collection('locations').document(jsonData["name"]).set({
'name': jsonData["jpName"],
'building': jsonData["schoolBuilding"],
'stair': jsonData["stair"],
'description': jsonData["description"],
'pannellum': jsonData["pannellum"],
'prev': jsonData["prev"],
'next': jsonData["next"],
'near': jsonData["near"],
'updateAt': firestore.SERVER_TIMESTAMP
})
else:
print("enter location name:")
locationName = input()
jsonData = json.load(open("public/data/"+locationName+".json", 'r', encoding="utf-8_sig"))
print(jsonData)
db.collection('locations').document(jsonData["name"]).set({
'name': jsonData["jpName"],
'building': jsonData["schoolBuilding"],
'stair': jsonData["stair"],
'description': jsonData["description"],
'pannellum': jsonData["pannellum"],
'prev': jsonData["prev"],
'next': jsonData["next"],
'near': jsonData["near"],
'updateAt': firestore.SERVER_TIMESTAMP
})