From ff155b339e11edd8007b95f4a8220d1f6ee70048 Mon Sep 17 00:00:00 2001 From: 13315423919 <13315423919@qq.com> Date: Fri, 7 Nov 2025 09:05:47 +0800 Subject: [PATCH] Add File --- run.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 run.py diff --git a/run.py b/run.py new file mode 100644 index 0000000..b527b25 --- /dev/null +++ b/run.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +""" +LandPPT Application Runner + +This script starts the LandPPT FastAPI application with proper configuration. +""" + +import uvicorn +import sys +import os +from dotenv import load_dotenv + +# Add src to Python path +sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) + +# Load environment variables with error handling +try: + load_dotenv() +except PermissionError as e: + print(f"Warning: Could not load .env file due to permission error: {e}") + print("Continuing with system environment variables...") +except Exception as e: + print(f"Warning: Could not load .env file: {e}") + print("Continuing with system environment variables...") + +def main(): + """Main entry point for running the application""" + + # Get configuration from environment variables with defaults + host = os.getenv("HOST", "0.0.0.0") + port = int(os.getenv("PORT", "8000")) + reload = os.getenv("RELOAD", "true").lower() in ("true", "1", "yes", "on") + log_level = os.getenv("LOG_LEVEL", "info").lower() + + # Configuration + config = { + "app": "landppt.main:app", + "host": host, + "port": port, + "reload": reload, + "log_level": log_level, + "access_log": True, + } + + print("šŸš€ Starting LandPPT Server...") + print(f"šŸ“ Host: {config['host']}") + print(f"šŸ”Œ Port: {config['port']}") + print(f"šŸ”„ Reload: {config['reload']}") + print(f"šŸ“Š Log Level: {config['log_level']}") + print(f"šŸ“ Server will be available at: http://localhost:{config['port']}") + print(f"šŸ“š API Documentation: http://localhost:{config['port']}/docs") + print(f"🌐 Web Interface: http://localhost:{config['port']}/web") + print("=" * 60) + + try: + uvicorn.run(**config) + except KeyboardInterrupt: + print("\nšŸ‘‹ Server stopped by user") + except Exception as e: + print(f"āŒ Error starting server: {e}") + sys.exit(1) + +if __name__ == "__main__": + main()