112 lines
3.1 KiB
Python
Executable File
112 lines
3.1 KiB
Python
Executable File
#!/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()
|
|
|
|
# Verify app.py exists
|
|
print("[3/4] Verifying application files...")
|
|
app_path = os.path.join(os.path.dirname(__file__), "app.py")
|
|
if not os.path.exists(app_path):
|
|
print(f"ERROR: app.py not found at {app_path}")
|
|
input("Press Enter to exit...")
|
|
return False
|
|
print("✓ Application found: app.py\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(os.path.dirname(__file__))
|
|
|
|
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)
|