-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
38 lines (25 loc) · 917 Bytes
/
server.py
File metadata and controls
38 lines (25 loc) · 917 Bytes
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
from http.server import BaseHTTPRequestHandler, HTTPServer
presence_filename= "./blueping.txt"
class ServerRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
request_path = self.path
if "key" in request_path:
try:
with open(presence_filename, "r") as file:
msg = file.read()
# print(msg)
self.wfile.write(bytes(msg, "ascii"))
except FileNotFoundError:
pass
return
def run(ip, port):
print('Starting server...')
# For port 80 you need root access
server_address = (ip, port)
httpd = HTTPServer(server_address, ServerRequestHandler)
print('Running server ', server_address)
httpd.serve_forever()
run('0.0.0.0', 8066)