From 8fab59a493c2a79ffa4623b05f7945dc4fd4f0ee Mon Sep 17 00:00:00 2001 From: pstruebi Date: Tue, 11 Mar 2025 08:51:02 +0100 Subject: [PATCH] refractoring --- frontend.py => auracaster-webui.py | 0 main_mock.py | 55 +++++++++++++++++++ mock_backend/__init__.py | 3 + api.py => mock_backend/mock_api.py | 4 +- .../mock_backend.py | 0 5 files changed, 60 insertions(+), 2 deletions(-) rename frontend.py => auracaster-webui.py (100%) create mode 100644 main_mock.py create mode 100644 mock_backend/__init__.py rename api.py => mock_backend/mock_api.py (93%) rename backend_model.py => mock_backend/mock_backend.py (100%) diff --git a/frontend.py b/auracaster-webui.py similarity index 100% rename from frontend.py rename to auracaster-webui.py diff --git a/main_mock.py b/main_mock.py new file mode 100644 index 0000000..042b787 --- /dev/null +++ b/main_mock.py @@ -0,0 +1,55 @@ +""" +Main entry point for the Airport Announcement System. +This script starts both the backend API and the Streamlit frontend. +""" +import subprocess +import sys +import time +import os +from pathlib import Path + +def start_backend(): + """Start the backend API server.""" + print("Starting backend API server...") + backend_process = subprocess.Popen( + [sys.executable, "-m", "uvicorn", "mock_backend.mock_api:app", "--host", "0.0.0.0", "--port", "7999", "--reload"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + # Wait a moment to ensure the backend has started + time.sleep(2) + return backend_process + +def start_frontend(): + """Start the Streamlit frontend.""" + print("Starting Streamlit frontend...") + frontend_process = subprocess.Popen( + [sys.executable, "-m", "streamlit", "run", "auracaster-webui.py"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + return frontend_process + +if __name__ == "__main__": + # Ensure we're in the correct directory + os.chdir(Path(__file__).parent) + + # Start the backend and frontend + backend_process = start_backend() + frontend_process = start_frontend() + + print("Airport Announcement System is running!") + print("Backend API: http://localhost:7999") + print("Frontend: http://localhost:8501") + + try: + # Keep the main process running + while True: + time.sleep(1) + except KeyboardInterrupt: + print("\nShutting down Airport Announcement System...") + backend_process.terminate() + frontend_process.terminate() + print("Shutdown complete.") diff --git a/mock_backend/__init__.py b/mock_backend/__init__.py new file mode 100644 index 0000000..aa25c4c --- /dev/null +++ b/mock_backend/__init__.py @@ -0,0 +1,3 @@ +""" +Mock backend for the Airport Announcement System. +""" diff --git a/api.py b/mock_backend/mock_api.py similarity index 93% rename from api.py rename to mock_backend/mock_api.py index 5a7e789..f4bd04e 100644 --- a/api.py +++ b/mock_backend/mock_api.py @@ -1,5 +1,5 @@ from fastapi import FastAPI, HTTPException -from backend_model import announcement_system, EndpointGroup, AnnouncementStates +from mock_backend.mock_backend import announcement_system, EndpointGroup from typing import List import uvicorn @@ -63,4 +63,4 @@ def get_available_endpoints(): return announcement_system.available_endpoints if __name__ == "__main__": - uvicorn.run('api:app', host="0.0.0.0", port=7999, reload=True) + uvicorn.run('mock_backend.mock_api:app', host="0.0.0.0", port=7999, reload=True) diff --git a/backend_model.py b/mock_backend/mock_backend.py similarity index 100% rename from backend_model.py rename to mock_backend/mock_backend.py