forked from alanxjin/smart-parking-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.py
36 lines (25 loc) · 768 Bytes
/
firebase.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
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from datetime import datetime
cred = credentials.Certificate('ismart-parking-meter-firebase-adminsdk-7ed7y-9a268ab07d.json')
firebase_admin.initialize_app(cred)
db = firestore.client()
# Change this
slot = u'slot3'
def startParking(slot):
now = datetime.now()
current_time = now.strftime(u"%H:%M:%S")
slots_ref = db.collection(u'slots').document(slot)
slots_ref.update({
u'availability': 0,
u'start_time': current_time
})
def endParking(slot):
slots_ref = db.collection(u'slots').document(slot)
slots_ref.update({
u'availability': 1,
u'start_time': None
})
startParking(slot)
# endParking(slot)