diff --git a/pagebot.py b/pagebot.py index f0f1fe6..5fcc557 100644 --- a/pagebot.py +++ b/pagebot.py @@ -5,7 +5,6 @@ import subprocess import time import secrets_file import threading -from datetime import datetime from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler import speech_recognition as sr @@ -93,42 +92,20 @@ async def upload_to_discord(mp4_file,text): else: print(f"Could not find channel with ID {channel}") -from datetime import datetime - def launch_and_watch(program_path): program_directory = os.path.dirname(program_path) - restart_time = secrets_file.restart_time # Format: "HH:MM" or None - - # Parse the restart time only if it's specified - if restart_time: - restart_hour, restart_minute = map(int, restart_time.split(":")) - while True: - # Launch the TTD program - process = subprocess.Popen(program_path, cwd=program_directory) + process = subprocess.Popen(program_path,cwd=program_directory) + process.wait() + if process.returncode != 0: + print("TTD has crashed. Relaunching...") + else: + print("TTD has exited normally.") + break - while True: - # Check every minute if it's time to restart TTD (only if restart_time is set) - if restart_time: - current_time = datetime.now() - if current_time.hour == restart_hour and current_time.minute == restart_minute: - print(f"Scheduled restart time reached ({restart_time}). Restarting TTD...") - process.terminate() # Terminate the current process - process.wait() # Wait for the process to exit - break # Exit inner loop to relaunch TTD - - # Check if TTD has crashed - if process.poll() is not None: - print("TTD has crashed. Relaunching...") - break # Exit inner loop to relaunch TTD - - # Sleep for a short interval before checking again - time.sleep(60) # Check once every minute - - # Wait for a few seconds before relaunching after crash or scheduled restart + # Wait for a few seconds before relaunching time.sleep(2) - if __name__ == "__main__": ## initialize watchdogs diff --git a/sample-secrets_file.py b/sample-secrets_file.py index 2fc90c0..541ff8d 100644 --- a/sample-secrets_file.py +++ b/sample-secrets_file.py @@ -13,6 +13,4 @@ delete_after_upload=True ## This will slow down pages and is unreliable. speech_to_text = True ## The background image for the video. -image_path = "img/blacksmall.jpg" -## time to restart daily, "None" to disable -restart_time = "02:00" \ No newline at end of file +image_path = "img/blacksmall.jpg" \ No newline at end of file