from http.server import HTTPServer
import http.server
import os
import time

BIND_HOST = '192.168.40.105'
PORT = 8000

class SimpleHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): 
    def do_GET(self):
        super().do_GET()
        file_path = str(self.path).lstrip("/")
        if file_path == "request.txt":
            open('request.txt', 'w').close()
        elif file_path == "result.txt":
            with open('result.txt', 'w') as f: f.write("") 


    def do_POST(self):
        content_length = int(self.headers.get('content-length', 0)) #size of data 
        body = self.rfile.read(content_length) #data itself 

        self.send_response(200) #status code 
        self.end_headers()
#        self.wfile.write(body)
        with open('result.txt', 'w') as f: 
            f.write(body.decode('utf-8'))

print(f'Listening on https://{BIND_HOST}:{PORT}\n')
httpd = HTTPServer((BIND_HOST, PORT), SimpleHTTPRequestHandler)
httpd.serve_forever() 
