import http.server
import socketserver
import webbrowser
import os

PORT = 8000

# Changer le répertoire de travail vers le dossier de votre site
web_dir = os.path.join(os.path.dirname(__file__), '.')
os.chdir(web_dir)

# Configurer le handler
Handler = http.server.SimpleHTTPRequestHandler

# Démarrer le serveur
with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print(f"Serveur démarré sur http://localhost:{PORT}")
    webbrowser.open(f'http://localhost:{PORT}')
    print("Appuyez sur Ctrl+C pour arrêter le serveur")
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print("\nServeur arrêté")