-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_dashboard.py
More file actions
executable file
·146 lines (118 loc) · 4.36 KB
/
Copy pathrun_dashboard.py
File metadata and controls
executable file
·146 lines (118 loc) · 4.36 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
#!/usr/bin/env python3
"""
Lookout MRA Desktop Dashboard Launcher
This script provides an easy way to start the dashboard with proper configuration
and error handling for desktop deployment.
"""
import os
import sys
import logging
import webbrowser
import time
from threading import Timer
def setup_logging():
"""Setup logging for the launcher"""
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
return logging.getLogger(__name__)
def check_dependencies():
"""Check if all required dependencies are installed"""
logger = logging.getLogger(__name__)
missing_deps = []
try:
import flask
import requests
import openpyxl
from dotenv import load_dotenv # This is how python-dotenv is imported
except ImportError as e:
missing_deps.append(str(e).split("'")[1])
if missing_deps:
logger.error("Missing required dependencies:")
for dep in missing_deps:
logger.error(f" - {dep}")
logger.error("Please install dependencies with: pip install -r requirements.txt")
return False
return True
def check_configuration():
"""Check basic configuration"""
logger = logging.getLogger(__name__)
# Load environment variables
from dotenv import load_dotenv
load_dotenv()
# Import config after loading env vars
from config import get_config
config_class = get_config()
# Validate configuration
issues = config_class.validate_config()
if issues:
logger.warning("Configuration issues found:")
for issue in issues:
logger.warning(f" - {issue}")
if not config_class.USE_SAMPLE_DATA:
logger.error("Cannot start in production mode with configuration issues")
return False
return True
def open_browser(url, delay=2):
"""Open browser after a delay"""
def _open():
try:
webbrowser.open(url)
except Exception as e:
print(f"Could not open browser automatically: {e}")
print(f"Please open your browser and navigate to: {url}")
Timer(delay, _open).start()
def main():
"""Main launcher function"""
logger = setup_logging()
print("="*60)
print("🛡️ LOOKOUT MRA DESKTOP DASHBOARD")
print("="*60)
# Check dependencies
logger.info("Checking dependencies...")
if not check_dependencies():
sys.exit(1)
# Check configuration
logger.info("Checking configuration...")
if not check_configuration():
sys.exit(1)
# Import and start the app
try:
from config import get_config, print_config_summary
config_class = get_config()
# Print configuration summary
print_config_summary()
# Prepare browser URL
url = f"http://{config_class.HOST}:{config_class.PORT}"
print(f"🚀 Starting dashboard server...")
print(f"📱 Dashboard will be available at: {url}")
print(f"🔄 Mode: {'Sample Data' if config_class.USE_SAMPLE_DATA else 'Production API'}")
print("="*60)
# Open browser automatically (with delay)
if config_class.HOST in ['127.0.0.1', 'localhost']:
logger.info("Will open browser automatically in 3 seconds...")
open_browser(url, delay=3)
# Import and run the Flask app
from app import create_app, _start_background_refresh_if_needed
app = create_app()
_start_background_refresh_if_needed(app)
app.run(
debug=config_class.DEBUG,
host=config_class.HOST,
port=config_class.PORT,
threaded=config_class.ENABLE_THREADING
)
except KeyboardInterrupt:
logger.info("Dashboard stopped by user")
print("\n👋 Dashboard stopped. Thank you for using Lookout MRA Dashboard!")
except Exception as e:
logger.error(f"Failed to start dashboard: {e}")
print(f"\n❌ Error: {e}")
print("\nTroubleshooting tips:")
print("1. Check that all dependencies are installed: pip install -r requirements.txt")
print("2. Verify your .env file configuration")
print("3. Ensure the port is not already in use")
sys.exit(1)
if __name__ == '__main__':
main()