import time import os import psutil import requests import json import subprocess from…
- User
import time import os import psutil import requests import json import subprocess from datetime import datetime
Discord webhook configuration
with open("webhook.txt", "r") as f: webhook_url = f.read().strip()
reopened_count = 0 checks_count = 0 last_restart_time = time.time() message_id = None
Set the restart interval and check interval
restart_interval = 20 * 60 # 20 minutes check_interval = 5 # 5 seconds
Logo
logo_color = '\033[92m' # Green logo = r""" {logo_color}
/ | | | | __ \ | | | |
| | _ __ __ _ | | | | | | | | ___ | | ___ _ __ | | | '/ ` / | ' \ | | | |/ _ \ __/ _ / __| / _ | '| | || | | (| _ \ | | | | || | __/ || / (| || () | |
_|| _,|/| || |/ _|__|_|___/|_|""".format(logo_color=logo_color)
os.system('cls') print(logo) print("\nTotal restarts: {reopened_count}") print(f"Checks: {checks_count}") print() print("Made By BearXxX#1940") print("\n")
def send_webhook_update(): global message_id current_time = datetime.now().strftime("Today at %H:%M") webhook_data = { "embeds": [{ "title": "Crash Detector", "description": "The program crash detector is running.", "color": 0x7FFF00, "fields": [ { "name": "Total Restarts", "value": str(reopened_count), "inline": True }, { "name": "Total Checks", "value": str(checks_count), "inline": True } ], "footer": { "text": f"Made by BearXxX#1940 | {current_time}" } }] } headers = {"Content-Type": "application/json"}
if message_id is None: response = requests.post(webhook_url, json=webhook_data, headers=headers) if response.status_code == 200: message_id = response.json()["id"] print("Discord webhook sent successfully.") else: print("Error sending Discord webhook.") else: edit_url = f"{webhook_url}/messages/{message_id}" response = requests.patch(edit_url, json=webhook_data, headers=headers) if response.status_code == 200: print("Discord webhook updated successfully.") else: print("Error updating Discord webhook.")...
GREEN_COLOR = '\033[91m' # Red RESET_COLOR = '\033[0m' # Reset color (\033[0m)
...
while True: if time.time() - last_restart_time >= restart_interval: checks_count = 0 for process in psutil.process_iter(): if process.name() == 'python.exe' and process.pid != os.getpid(): process.terminate() reopened_count += 1 last_restart_time = time.time() os.system('cls') print(GREEN_COLOR + logo + RESET_COLOR) print("") print(f"{GREEN_COLOR}Total restarts: {reopened_count}{RESET_COLOR}") print(f"{GREEN_COLOR}Checks: {checks_count}{RESET_COLOR}") print(f"{GREEN_COLOR}Made By BearXxX#1940{RESET_COLOR}") print("") print("") send_webhook_update() time.sleep(5)
for process in psutil.process_iter(): if process.name() == 'python.exe' and 'main.py' in process.cmdline(): break else: checks_count += 1 last_restart_time = time.time() os.system('cls') print(GREEN_COLOR + logo + RESET_COLOR) print("") print(f"{GREEN_COLOR}Total restarts: {reopened_count}{RESET_COLOR}") print(f"{GREEN_COLOR}Checks: {checks_count}{RESET_COLOR}") print(f"{GREEN_COLOR}Made By BearXxX#1940{RESET_COLOR}") print("") print("") send_webhook_update() subprocess.Popen(['python', 'main.py'], cwd=os.path.dirname(os.path.abspath(__file__)), creationflags=subprocess.CREATE_NEW_CONSOLE) send_webhook_update() time.sleep(check_interval)make this into a white window with all the stats what are on the program but on a window with a start/stop button with how many seconds ran at the bottom
USE THE GUI library Tkinter
make the window/gui look very nice
- Assistant
You can create a GUI application using Tkinter to achieve your requirements. Here's an example of how you can create a window with a start/stop button and stats display:
import tkinter as tk from tkinter import ttk # Global variables started = False seconds_ran = 0 def start_stop(event=None): global started if started: # Stop the process started = False start_stop_button.config(text="Start") # Add your code to stop monitoring the program here else: # Start the process started = True start_stop_button.config(text="Stop") # Add your code to start monitoring the program here # Create the main window root = tk.Tk() root.title("Crash Detector") # Create and configure the main frame main_frame = ttk.Frame(root, padding="10") main_frame.grid(column=0, row=0, sticky=(tk.W, tk.E, tk.N, tk.S)) root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) # Logo logo_label = ttk.Label(main_frame, text="Crash Detector", font=("Helvetica", 24)) logo_label.grid(column=0, row=0, columnspan=2, pady=10) # Stats restarts_label = ttk.Label(main_frame, text="Total Restarts: 0", font=("Helvetica", 14)) restarts_label.grid(column=0, row=1, sticky=tk.W) checks_label = ttk.Label(main_frame, text="Total Checks: 0", font=("Helvetica", 14)) checks_label.grid(column=1, row=1, sticky=tk.W) # Start/Stop button start_stop_button = ttk.Button(main_frame, text="Start", command=start_stop) start_stop_button.grid(column=0, row=2, pady=10) # Time ran time_ran_label = ttk.Label(main_frame, text="Time Ran: 0 seconds", font=("Helvetica", 14)) time_ran_label.grid(column=0, row=3, columnspan=2) # Bind the space bar to the start/stop function root.bind("<space>", start_stop) # Start the main loop root.mainloop()This code creates a simple tkinter GUI window with a start/stop button, stats display, and title. You can customize it further according to your requirements and add/update the stats and functions to monitor the program.
Note: You should integrate the existing functionality of your crash detector code into the window by placing it inside the respective start and stop sections of the
start_stopfunction. Also, to update the displayed stats, you can modify the text property of the respective labels (restarts_label,checks_label, andtime_ran_label) as needed.