-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (48 loc) · 1.88 KB
/
app.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
from time import sleep
from pubsub import pub
from smart_bar import SmartBar
from order_manager import OrderManager
from threading import Thread
import requests
class App:
def run(self):
self.setup()
self.loop()
def setup(self):
print("Create App")
requests.get('http://smart-bar-app.herokuapp.com/api/orders/delete_all')
pub.subscribe(self.notify, pub.ALL_TOPICS)
self.order_manager = OrderManager()
self.smart_bar = SmartBar()
order_manager_thread = Thread(target = self.order_manager.run, daemon = True)
order_manager_thread.start()
def loop(self):
order = {}
try:
while True:
if not self.smart_bar.isProcessing() and bool(order):
pub.sendMessage('order-creating', status='creating')
self.smart_bar.processDrink(order["drink"])
requests.get('http://smart-bar-app.herokuapp.com/api/orders/delete_all')
order = {}
elif self.smart_bar.isProcessing() == False:
order = self.getNewOrder()
if (self.order_manager.cancel):
print(self.order_manager.cancel)
self.smart_bar.stop()
self.order_manager.cancel = False
sleep(0.1)
print("Done making orders")
except KeyboardInterrupt:
print ("\nCtrl-C pressed.")
self.smart_bar.stop()
def notify(self, topicObj=pub.AUTO_TOPIC, **msgData):
status = False
if bool(msgData) and msgData['status']:
status = msgData['status']
self.order_manager.queueUpdateOrder(topicObj.getName(), status)
print('topic "%s": %s' % (topicObj.getName(), msgData))
def getNewOrder(self):
return self.order_manager.getLatestOrder()
app = App()
app.run()