import http.server
import socketserver
import urllib.parse
import os

PORT = 8000

class WheelHandler(http.server.SimpleHTTPRequestHandler):
    def do_POST(self):
        if self.path == '/save-result':
            content_length = int(self.headers['Content-Length'])
            post_data = self.rfile.read(content_length).decode('utf-8')
            winner = urllib.parse.parse_qs(post_data).get('winner', [''])[0]
            
            if winner:
                # Append the winner to blacklist.conf on a new line
                with open("blacklist.conf", "a") as f:
                    f.write(f"{winner}\n")
                print(f"Added to blacklist: {winner}")
            
            self.send_response(200)
            self.end_headers()
            self.wfile.write(b"Success")
        else:
            super().do_POST()

print(f"Wheel Server running at http://localhost:{PORT}/overlay.html  Admin Panel Running On http://localhost:{PORT}/admin.html")
with socketserver.TCPServer(("", PORT), WheelHandler) as httpd:
    httpd.serve_forever()