forked from marusak/verbose-potato
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
24 lines (20 loc) · 863 Bytes
/
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
import sys
import http.server
import socketserver
import subprocess
class httpRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path in ["/date", "/time"]:
self.path = "static" + self.path + ".html"
return http.server.SimpleHTTPRequestHandler.do_GET(self)
elif self.path == "/":
self.path = "static/index.html"
return http.server.SimpleHTTPRequestHandler.do_GET(self)
conf = subprocess.run(["grep", "port=", "/var/tmp/mytime/mytime.conf"], stdout=subprocess.PIPE)
if b"=" not in conf.stdout:
print("Could not read configuration file `/var/tmp/mytime/mytime.conf`")
sys.exit(1)
port = conf.stdout.split(b"=")[1]
socketserver.TCPServer.allow_reuse_address = True
server = socketserver.TCPServer(("", int(port)), httpRequestHandler)
server.serve_forever()