-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
161 lines (134 loc) · 5.09 KB
/
Copy pathstart.py
File metadata and controls
161 lines (134 loc) · 5.09 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
"""
IITian Academy Milestone Tracker - Simple Startup Script
Fixed import issues for direct execution
"""
import os
import sys
import uvicorn
from pathlib import Path
# Add the project root to Python path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
def print_banner():
"""Print application banner"""
banner = """
╔══════════════════════════════════════════════════════════════╗
║ 🎓 IITian Academy Milestone Tracker ║
║ Professional Project Management ║
╚══════════════════════════════════════════════════════════════╝
"""
print(banner)
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 8):
print("❌ Error: Python 3.8 or higher is required")
print(f"Current version: {sys.version}")
sys.exit(1)
print(f"✅ Python version: {sys.version.split()[0]}")
def check_environment_file():
"""Check if .env file exists and create from template if needed"""
env_file = Path(".env")
env_example = Path(".env.example")
if not env_file.exists():
if env_example.exists():
print("📄 Creating .env file from template...")
with open(env_example, 'r') as src, open(env_file, 'w') as dst:
dst.write(src.read())
print("⚠️ Please edit .env file with your actual values before running the server")
return False
else:
print("❌ Error: .env.example file not found")
return False
print("✅ Environment file found")
return True
def install_dependencies():
"""Install Python dependencies"""
print("📦 Installing dependencies...")
try:
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
check=True, capture_output=True)
print("✅ Dependencies installed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Error installing dependencies: {e}")
return False
def create_directories():
"""Create necessary directories"""
directories = ["backups", "static", "templates"]
for dir_name in directories:
Path(dir_name).mkdir(exist_ok=True)
print("✅ Application directories ready")
def validate_env_variables():
"""Validate required environment variables"""
from dotenv import load_dotenv
load_dotenv()
required_vars = [
"MONGODB_URI",
"ADMIN_API_KEY",
"DATABASE_NAME"
]
missing_vars = []
for var in required_vars:
if not os.getenv(var):
missing_vars.append(var)
if missing_vars:
print(f"❌ Missing required environment variables: {', '.join(missing_vars)}")
print("Please update your .env file with the correct values")
return False
print("✅ Environment variables validated")
return True
def get_server_config():
"""Get server configuration from environment"""
from dotenv import load_dotenv
load_dotenv()
return {
"host": os.getenv("HOST", "127.0.0.1"),
"port": int(os.getenv("PORT", 8000)),
"reload": True,
"log_level": "info"
}
def start_server(config):
"""Start the FastAPI server"""
print(f"🚀 Starting server at http://{config['host']}:{config['port']}")
print("📊 Dashboard: http://localhost:8000")
print("📚 API Docs: http://localhost:8000/docs")
print("🔍 Health Check: http://localhost:8000/health")
print("\n🔑 Admin Panel: Click 'Admin Panel' button on dashboard")
print("📱 Public View: Default dashboard view for clients")
print("\nPress Ctrl+C to stop the server\n")
try:
import uvicorn
uvicorn.run(
"app.main:app",
host=config["host"],
port=config["port"],
reload=config["reload"],
log_level=config["log_level"]
)
except KeyboardInterrupt:
print("\n👋 Server stopped by user")
except Exception as e:
print(f"❌ Server error: {e}")
def main():
"""Main startup function"""
print_banner()
# Check system requirements
check_python_version()
# Setup environment
if not check_environment_file():
return
# Install dependencies
if not install_dependencies():
return
# Create directories
create_directories()
# Validate configuration
if not validate_env_variables():
return
# Get server configuration
config = get_server_config()
# Start server
start_server(config)
if __name__ == "__main__":
main()