-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
72 lines (59 loc) · 1.81 KB
/
start.py
File metadata and controls
72 lines (59 loc) · 1.81 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
#!/usr/bin/env python3
"""
Startup script for the LinkedIn Automater application
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def check_environment():
"""Check if all required environment variables are set"""
required_vars = [
"SQLALCHEMY_DATABASE_URL",
"SECRET_KEY",
"OPENAI_API_KEY",
"USERNAME",
"PASSWORD"
]
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)}")
return False
print("✅ All required environment variables are set")
return True
def test_database():
"""Test database connection"""
try:
from database import engine
from sqlalchemy import text
with engine.connect() as connection:
connection.execute(text("SELECT 1"))
print("✅ Database connection successful")
return True
except Exception as e:
print(f"❌ Database connection failed: {e}")
return False
def main():
"""Main startup function"""
print("🚀 Starting LinkedIn Automater...")
# Check environment variables
if not check_environment():
sys.exit(1)
# Test database connection
if not test_database():
sys.exit(1)
# Import and start the application
try:
import uvicorn
from app import api # Import api from app.py instead of app from main.py
print("✅ Application ready to start")
uvicorn.run(api, host="0.0.0.0", port=8000)
except Exception as e:
print(f"❌ Failed to start application: {e}")
sys.exit(1)
if __name__ == "__main__":
main()