-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebaseservice.py
88 lines (70 loc) · 3.03 KB
/
firebaseservice.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
81
82
83
84
85
86
87
88
from firebase import firebase
from datetime import datetime
import time
class FirebaseService:
__url = 'https://ntnt-1999.firebaseio.com/'
def __init__(self):
self.app = firebase.FirebaseApplication('https://ntnt-1999.firebaseio.com/', authentication=None)
now = datetime.now()
self.year = now.year
self.month = now.month
self.day = now.day
self.link = '{0}/{1}/{2}'.format(self.year, self.month, self.day)
self.linkToProducts = self.link + '/products'
self.startTime = now.strftime('%H:%M:%S')
if self.app.get('/{0}'.format(self.year),'') == None:
self.app.put('/',str(year),{
str(month) : {
str(day):{
'history':{
self.startTime : ''
},
'status' : True
}
}
})
elif self.app.get('/{0}/{1}'.format(self.year, self.month),'') == None:
self.app.put('/{0}'.format(self.year),str(self.month),{
str(self.day) : {
'history':{
self.startTime : ''
},
'status' : True
}
})
elif self.app.get('/{0}/{1}/{2}'.format(self.year, self.month, self.day),'') == None:
self.app.put('/{0}/{1}'.format(self.year,self.month),str(self.day),{
'history':{
self.startTime : ''
},
'status' : True
})
else:
self.app.put(self.link, 'status', True)
self.app.put(self.link + '/history', self.startTime, '')
self.dataProducts = self.app.get(self.linkToProducts,'')
def updateProducts(self, productsForDetecting):
self.dataProducts = self.app.get(self.link,'products')
if self.dataProducts == None:
dictProduct = {}
for product in productsForDetecting:
dictProduct[product] = 0
self.app.put(self.link, 'products', dictProduct)
else:
print('testinggggg')
for product in productsForDetecting:
if(product not in self.dataProducts):
self.app.put(self.linkToProducts, product, 0)
self.dataProducts = self.app.get(self.linkToProducts,'')
def addOneProduct(self, productName):
self.dataProducts[productName] += 1
def setStatusToFalse(self):
self.app.put(self.link,'status', False)
now = datetime.now()
endTime = now.strftime('%H:%M:%S')
self.app.put(self.link + '/history', self.startTime, endTime)
def updateProductQuantityThread(self):
while(1):
self.app.put(self.link,'products',self.dataProducts)
print(self.dataProducts)
time.sleep(10)