-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.py
More file actions
135 lines (114 loc) · 3.95 KB
/
start.py
File metadata and controls
135 lines (114 loc) · 3.95 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
#!/usr/bin/env python3
"""
Startup Script for Health-Aware Recipe Modifier
This script checks dependencies, sets up the database, and starts the application.
"""
import os
import sys
import subprocess
import importlib.util
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 7):
print("❌ Python 3.7 or higher is required")
print(f"Current version: {sys.version}")
return False
print(f"✅ Python version: {sys.version.split()[0]}")
return True
def check_dependencies():
"""Check if required packages are installed"""
required_packages = [
'flask',
'pymongo',
'reportlab',
'python-dateutil'
]
missing_packages = []
for package in required_packages:
spec = importlib.util.find_spec(package)
if spec is None:
missing_packages.append(package)
else:
print(f"✅ {package} is installed")
if missing_packages:
print(f"\n❌ Missing packages: {', '.join(missing_packages)}")
print("Installing missing packages...")
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install'] + missing_packages)
print("✅ All packages installed successfully")
except subprocess.CalledProcessError:
print("❌ Failed to install packages")
return False
return True
def check_mongodb():
"""Check if MongoDB is accessible"""
try:
from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/', serverSelectionTimeoutMS=5000)
client.server_info()
print("✅ MongoDB is running and accessible")
return True
except Exception as e:
print("❌ MongoDB connection failed")
print("Please make sure MongoDB is running on localhost:27017")
print("You can:")
print(" 1. Install MongoDB locally")
print(" 2. Use MongoDB Atlas (cloud)")
print(" 3. Update the connection string in app.py")
return False
def setup_database():
"""Set up the database with sample data"""
try:
from database_setup import setup_database
print("\n🗄️ Setting up database...")
setup_database()
return True
except Exception as e:
print(f"❌ Database setup failed: {e}")
return False
def create_directories():
"""Create necessary directories"""
directories = ['reports', 'static', 'templates']
for directory in directories:
if not os.path.exists(directory):
os.makedirs(directory)
print(f"✅ Created directory: {directory}")
else:
print(f"✅ Directory exists: {directory}")
def start_application():
"""Start the Flask application"""
print("\n🚀 Starting Health-Aware Recipe Modifier...")
print("The application will be available at: http://localhost:5000")
print("Press Ctrl+C to stop the application")
print("-" * 50)
try:
from app import app
app.run(debug=True, host='0.0.0.0', port=5000)
except KeyboardInterrupt:
print("\n👋 Application stopped by user")
except Exception as e:
print(f"❌ Failed to start application: {e}")
def main():
"""Main startup function"""
print("🧠 Health-Aware Recipe Modifier - Startup")
print("=" * 50)
# Check Python version
if not check_python_version():
return
# Check dependencies
if not check_dependencies():
return
# Create directories
create_directories()
# Check MongoDB
if not check_mongodb():
print("\n💡 You can still run the application, but database features won't work")
response = input("Continue anyway? (y/n): ")
if response.lower() != 'y':
return
# Setup database
setup_database()
# Start application
start_application()
if __name__ == "__main__":
main()