#!/usr/bin/env python3 """ Startup script for Salesforce PDF Generator API """ import subprocess import sys import os def install_requirements(): """Install required packages""" print("Installing required packages...") try: subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) print("✅ Requirements installed successfully") except subprocess.CalledProcessError as e: print(f"❌ Failed to install requirements: {e}") return False return True def check_wkhtmltopdf(): """Check if wkhtmltopdf is available""" print("Checking wkhtmltopdf installation...") try: result = subprocess.run(['wkhtmltopdf', '--version'], capture_output=True, text=True) if result.returncode == 0: print("✅ wkhtmltopdf is available") return True else: print("❌ wkhtmltopdf not found in PATH") return False except FileNotFoundError: print("❌ wkhtmltopdf not found. Please install it:") print(" Ubuntu/Debian: sudo apt-get install wkhtmltopdf") print(" macOS: brew install wkhtmltopdf") print(" Windows: Download from https://wkhtmltopdf.org/downloads.html") return False def start_api(): """Start the Flask API server""" print("Starting Salesforce PDF Generator API...") try: from salesforce_pdf_api import app app.run(host='0.0.0.0', port=5000, debug=True) except ImportError as e: print(f"❌ Failed to import API: {e}") return False except Exception as e: print(f"❌ Failed to start API: {e}") return False return True def main(): """Main startup function""" print("🚀 Salesforce PDF Generator API Startup") print("=" * 50) # Install requirements if not install_requirements(): print("❌ Cannot continue without requirements") return # Check wkhtmltopdf if not check_wkhtmltopdf(): print("⚠️ wkhtmltopdf not available. PDF generation may fail.") print(" Continuing anyway...") # Start API print("\n🌐 Starting API server on http://localhost:8000") print(" Press Ctrl+C to stop") print("=" * 50) if not start_api(): print("❌ Failed to start API server") return if __name__ == "__main__": main()