-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
38 lines (29 loc) · 1.06 KB
/
server.py
File metadata and controls
38 lines (29 loc) · 1.06 KB
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 HTTPServer, SimpleHTTPRequestHandler
import logging
import sys
import os
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
# Define the handler to handle requests
class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
def log_message(self, format, *args):
logging.info("%s - %s" % (self.address_string(), format % args))
# Start a local HTTP server
def start_http_server(port):
server_address = ("", port)
httpd = HTTPServer(server_address, MyHTTPRequestHandler) # Use custom handler
print(f"HTTP server started at port {port}")
return httpd
def main():
PORT = 8000
logging.basicConfig(filename=f"{SCRIPT_DIR}/email_seen.log", level=logging.INFO)
sys.stdout = open(f"{SCRIPT_DIR}/email_seen.log", "a")
httpd = start_http_server(PORT)
try:
# Keep the program running until interrupted
httpd.serve_forever()
except KeyboardInterrupt:
# Close the HTTP server when interrupted
httpd.shutdown()
print("HTTP server stopped")
if __name__ == "__main__":
main()