-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve_food.py
45 lines (35 loc) · 1.04 KB
/
serve_food.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
import json
from food import Food
import tornado.ioloop
import tornado.web
PORT = 8081
FOOD = Food()
class MainHandler(tornado.web.RequestHandler):
def get(self):
arg = FOOD.choose().upper()
self.render('index.html', args=arg)
def post(self):
retVal = 'error'
req = self.get_argument('req', None)
arg = self.get_argument('arg', None)
if req:
if req == 'add':
if arg:
FOOD.add(arg)
retVal = 'success'
elif req == 'remove':
if arg:
FOOD.remove(arg)
retVal = 'success'
elif req == 'all':
retVal = json.dumps(FOOD.get_all())
elif req == 'choose':
retVal = FOOD.choose()
self.write(retVal)
application = tornado.web.Application([
(r"/", MainHandler)],
static_path="static",
debug=True)
if __name__ == "__main__":
application.listen(PORT)
tornado.ioloop.IOLoop.instance().start()