#!/usr/bin/env python3 """ Instagram Auto Poster - Production Entry Point """ import os import sys import threading import time from pathlib import Path # Add current directory to path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from web_interface import app from main import main as run_instagram_agent def run_agent_in_background(): """Run the Instagram agent in a separate thread""" try: # Give the web server time to start time.sleep(5) run_instagram_agent() except Exception as e: print(f"Error in Instagram agent: {e}") if __name__ == '__main__': # Create necessary directories os.makedirs('images', exist_ok=True) os.makedirs('images/posted', exist_ok=True) os.makedirs('logs', exist_ok=True) os.makedirs('templates', exist_ok=True) # Start Instagram agent in background thread agent_thread = threading.Thread(target=run_agent_in_background, daemon=True) agent_thread.start() # Get port from environment or default to 5000 port = int(os.environ.get('PORT', 5000)) # Run Flask app app.run(host='0.0.0.0', port=port, debug=False)