-
Notifications
You must be signed in to change notification settings - Fork 1
/
TornadoServer.py
executable file
·73 lines (56 loc) · 1.65 KB
/
TornadoServer.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
__author__ = 'suquark'
import os
import tornado
import oxfordcv
import picamera
from tornado.ioloop import IOLoop
import tornado.web
from tornado.web import RequestHandler, Application, authenticated
import json
class MainHandler(RequestHandler):
def get(self):
self.write('Hello world')
imgpath = ''
info = ''
class Refrigerator_Opened(RequestHandler):
def get(self):
print('Server: Set Path')
globals()['imgpath'] = './static/' + os.path.basename(self.get_argument('path'))
globals()['info'] = self.get_argument('info')
class polling(RequestHandler):
def get(self):
print('polling')
if globals()['info'] == '':
self.set_status(404)
else:
self.write(globals()['info'])
globals()['info'] = ''
class image(RequestHandler):
def get(self):
print('Getting image...')
pt = globals()['imgpath']
self.write(open(pt).read())
self.finish()
# self.redirect(pt)
class OCRHandler(RequestHandler):
def get(self):
camera = picamera.PiCamera()
camera.video_stabilization = True
print('Capturing picture...')
camera.capture('temp.jpg')
camera.close()
print('Analyzing...')
self.write(oxfordcv.ocr('temp.jpg', 'en'))
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static"),
}
application = Application([
(r"/", MainHandler),
(r"/ocr", OCRHandler),
(r"/Refrigerator_Opened", Refrigerator_Opened),
(r"/image", image),
(r"/poll", polling),
], **settings)
if __name__ == "__main__":
application.listen(8888)
IOLoop.instance().start()