-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·91 lines (72 loc) · 2.46 KB
/
server.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
89
90
91
#!/usr/bin/env python3
import tornado.autoreload
import tornado.ioloop
import tornado.web
import json
import subprocess
import os
import miami_api
import html_functions
class OpenLocationHandler(tornado.web.RequestHandler):
def get(self):
response = miami_api.get_open()
json_response = json.dumps(response, indent=4 * ' ')
self.set_header('Content-Type', 'application/json')
self.write(json_response)
class StatusHandler(tornado.web.RequestHandler):
def get(self, location):
response = miami_api.get_status(location)
json_response = json.dumps(response, indent=4 * ' ')
self.set_header('Content-Type', 'application/json')
self.write(json_response)
class PersonInfoHandler(tornado.web.RequestHandler):
def get(self, name):
response = miami_api.get_person_info(name)
json_response = json.dumps(response, indent=4 * ' ')
self.set_header('Content-Type', 'application/json')
self.write(json_response)
class TodayStatusHandler(tornado.web.RequestHandler):
def get(self):
response = miami_api.get_today_hours()
json_response = json.dumps(response, indent=4 * ' ')
self.set_header('Content-Type', 'application/json')
self.write(json_response)
class GithubHookHandler(tornado.web.RequestHandler):
def post(self):
subprocess.call(['git', 'pull', 'origin', 'master'])
self.write('Update completed sucessfully')
def get(self):
self.write('update?')
class MainHandler(tornado.web.RequestHandler):
def get(self, filename='index.html'):
if filename is '' or filename == 'index.html':
open_list = html_functions.get_open_for_html()
self.render('index.html', open_list=open_list)
return
if filename == 'api' or filename == 'api/' or filename == 'api.html':
open_list = miami_api.get_open()
url = self.request.uri
self.render('api.html', open_list = open_list, url = url)
return
self.render(filename)
handlers = [
(r'/api/open', OpenLocationHandler),
(r'/api/status/([a-zA-Z_]+)', StatusHandler),
(r'/api/today', TodayStatusHandler),
(r'/api/update', GithubHookHandler),
(r'/api/person/([a-zA-Z_+]+)', PersonInfoHandler),
(r'/(.*)', MainHandler),
(r'/', MainHandler)
]
settings = {
'debug': False,
'static_path': os.path.join('static'),
'template_path': os.path.join('templates')
}
application = tornado.web.Application(handlers, **settings)
if __name__ == '__main__':
application.listen(5000)
tornado.autoreload.watch('miami_server.py')
ioloop = tornado.ioloop.IOLoop.instance()
tornado.autoreload.start(ioloop)
ioloop.start()