-
Notifications
You must be signed in to change notification settings - Fork 1
/
firebase_manager.py
80 lines (61 loc) · 1.66 KB
/
firebase_manager.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from firebase_admin import auth
from datetime import datetime
import uuid
COLLECTION_NAME = 'map'
def generate_id(p):
return ''.join([str(x).replace('.', '|') for x in p])
def set_nodes(nodes):
firebase_admin.firestore.client(app=None) \
.collection(COLLECTION_NAME) \
.document('nodes') \
.set(nodes)
def add_node_data(name, data):
"""
:param name: dis is da node name
:param data: dis is da dict with da {macaddress: db and other stuff}
:return:
"""
firebase_admin.firestore.client(app=None) \
.collection(COLLECTION_NAME) \
.document('nodes') \
.update({
str(name): {
'aps': data
}
})
def get_nodes():
return firebase_admin.firestore.client(app=None) \
.collection(COLLECTION_NAME) \
.document('nodes') \
.get().to_dict()
"""
ok dis return this shit
{
"index shit of the node": {
"location": [x, y],
"aps" : {
"<mac>" : db,
....
}
}, ...
}
"""
def get_edges():
data = firebase_admin.firestore.client(app=None) \
.collection(COLLECTION_NAME) \
.document('edges')\
.get().to_dict()
good_data = []
if data:
for i in data:
good_data.append(data[i])
return good_data
def set_edge(edges):
for e in edges:
firebase_admin.firestore.client(app=None) \
.collection(COLLECTION_NAME) \
.document('edges')\
.update({generate_id(e): e})