-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (29 loc) · 1.05 KB
/
main.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
from display import RossumDisplay
import socket
from configuration import I2C_PINS, DISPLAY_RESOLUTION
def parse_url_parameter(content, parameter):
try:
text = content.split("\r\n")[0].split("GET")[-1].split("HTTP")[0].split("{}=".format(parameter))[-1].strip()
except IndexError:
return None
return text.replace("+", " ")
def process_request(connection):
content = str(conn.recv(1024))
text = parse_url_parameter(content, "text")
print(text)
display.show_text(text, y=20)
conn.send('HTTP/1.1 200 OK\n')
conn.send('Content-Type: application/json\n')
conn.send('Connection: close\n\n')
conn.send('{"status": "ok"}')
conn.close()
if __name__ == "__main__":
display = RossumDisplay(I2C_PINS["sda"], I2C_PINS["scl"], DISPLAY_RESOLUTION)
display.show_text("running")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
process_request(conn)