modified: app.py

This commit is contained in:
SimolZimol
2024-09-02 17:45:23 +02:00
parent 78f144535c
commit 4c2e269196

29
app.py
View File

@@ -1,4 +1,3 @@
# web_panel/app.py
from flask import Flask, render_template, redirect, url_for, request, session
import os
import subprocess
@@ -7,23 +6,33 @@ import psutil
app = Flask(__name__)
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
# Speichern der Prozess-ID
bot_process = None
def bot_status():
"""Überprüft, ob der Bot läuft."""
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
return True
return False
global bot_process
if bot_process is None:
return False
return bot_process.poll() is None # None bedeutet, dass der Prozess noch läuft
def start_bot():
"""Startet den Bot."""
subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
global bot_process
if not bot_status():
bot_process = subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
else:
print("Bot läuft bereits.")
def stop_bot():
"""Stoppt den Bot."""
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
proc.terminate()
break
global bot_process
if bot_process and bot_status():
bot_process.terminate()
bot_process.wait() # Warten, bis der Prozess beendet ist
bot_process = None
else:
print("Bot läuft nicht.")
@app.route("/")
def index():