#!/usr/bin/env python3 """ TV_APP V1.0.0 - One-Click Launcher Automatically installs dependencies and starts the web application """ import os import sys import subprocess import webbrowser import time import importlib.util def check_python_version(): """Check if Python 3.7+ is available""" if sys.version_info < (3, 7): print("ERROR: Python 3.7+ is required") print(f"You have Python {sys.version}") return False return True def check_and_install_flask(): """Check if Flask is installed, install if not""" flask_spec = importlib.util.find_spec("flask") if flask_spec is not None: import flask print(f"✓ Flask is installed: v{flask.__version__}") return True print("⚠ Flask not found. Installing...") try: subprocess.check_call([sys.executable, "-m", "pip", "install", "flask", "-q"]) print("✓ Flask installed successfully") return True except subprocess.CalledProcessError: print("ERROR: Failed to install Flask") return False def main(): """Main installation and startup routine""" print("\n" + "="*70) print(" TV_APP V1.0.0 - Installation & Launcher") print("="*70 + "\n") # Check Python version print("[1/4] Checking Python version...") if not check_python_version(): print("\nPlease install Python 3.7 or higher") input("Press Enter to exit...") return False import flask print(f"✓ Python {sys.version.split()[0]} found\n") # Check Flask print("[2/4] Checking Flask installation...") if not check_and_install_flask(): input("Press Enter to exit...") return False print() # Find the app directory (handle symlinks and copies) print("[3/4] Locating application directory...") # Start with script location script_dir = os.path.dirname(os.path.abspath(__file__)) # Resolve symlinks if os.path.islink(__file__): script_dir = os.path.dirname(os.path.abspath(os.readlink(__file__))) app_path = os.path.join(script_dir, "app.py") # If app.py not found, search for it if not os.path.exists(app_path): print(f" Searching for app.py near {script_dir}...") # Check parent directory parent_dir = os.path.dirname(script_dir) app_path = os.path.join(parent_dir, "app.py") if os.path.exists(app_path): script_dir = parent_dir else: print(f"ERROR: app.py not found") print(f" Checked: {script_dir}") print(f" Checked: {parent_dir}") input("Press Enter to exit...") return False print(f"✓ Application found: {app_path}\n") # Start the app print("[4/4] Starting web application...\n") print("="*70) print(" TV_APP is starting...") print("="*70) print("\nThe application will be available at: http://localhost:5000") print("Press Ctrl+C to stop the server\n") time.sleep(2) # Open browser try: webbrowser.open("http://localhost:5000", new=1) except: pass # Change to app directory and run os.chdir(script_dir) try: # Import and run the Flask app import app app.app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False) except ImportError as e: print(f"ERROR: Could not import app.py: {e}") input("Press Enter to exit...") return False except KeyboardInterrupt: print("\n\nServer stopped by user") return True except Exception as e: print(f"ERROR: {e}") input("Press Enter to exit...") return False return True if __name__ == "__main__": success = main() sys.exit(0 if success else 1)