Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
myon-bioinformatics authored Jun 14, 2023
1 parent f543cc2 commit d2e36fa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from urllib.parse import urlparse, parse_qs
import json

# Class for the control message
class ControlMessage:
def __init__(self, text, number):
self.text = text
Expand All @@ -10,14 +11,17 @@ def __init__(self, text, number):
def __str__(self):
return f"Text: {self.text}, Number: {self.number}"

# Request handler class
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
# Process GET requests
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(bytes("OK: It's a GET method or URL not in \"/admin\"", "utf-8"))

def do_POST(self):
# Process POST requests
if self.path.startswith("/admin"):
content_length = int(self.headers.get("Content-Length", 0))
body = self.rfile.read(content_length).decode("utf-8")
Expand All @@ -26,6 +30,7 @@ def do_POST(self):
number = params.get("number", [None])[0]

if text is None or not number.isdigit():
# Invalid request: missing text or number
self.send_response(400)
self.send_header("Content-type", "text/plain")
self.end_headers()
Expand All @@ -44,9 +49,11 @@ def do_POST(self):
self.end_headers()
self.wfile.write(bytes("OK: It's a GET method or URL not in \"/admin\"", "utf-8"))

# Process the control message
def process_message(message):
print(f"Accepted Control message: {message}")

# Start the server
def start_server():
host = "localhost"
port = 3020
Expand Down

0 comments on commit d2e36fa

Please sign in to comment.