Revert "add daily restart"

This reverts commit e8395f0b60.
This commit is contained in:
majmongoose 2024-10-25 11:21:15 -04:00
parent 45b65fc6fe
commit 8b00d683d6
2 changed files with 9 additions and 34 deletions

View File

@ -5,7 +5,6 @@ import subprocess
import time import time
import secrets_file import secrets_file
import threading import threading
from datetime import datetime
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
import speech_recognition as sr import speech_recognition as sr
@ -93,42 +92,20 @@ async def upload_to_discord(mp4_file,text):
else: else:
print(f"Could not find channel with ID {channel}") print(f"Could not find channel with ID {channel}")
from datetime import datetime
def launch_and_watch(program_path): def launch_and_watch(program_path):
program_directory = os.path.dirname(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: while True:
# Launch the TTD program
process = subprocess.Popen(program_path,cwd=program_directory) process = subprocess.Popen(program_path,cwd=program_directory)
process.wait()
while True: if process.returncode != 0:
# 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...") print("TTD has crashed. Relaunching...")
break # Exit inner loop to relaunch TTD else:
print("TTD has exited normally.")
break
# Sleep for a short interval before checking again # Wait for a few seconds before relaunching
time.sleep(60) # Check once every minute
# Wait for a few seconds before relaunching after crash or scheduled restart
time.sleep(2) time.sleep(2)
if __name__ == "__main__": if __name__ == "__main__":
## initialize watchdogs ## initialize watchdogs

View File

@ -14,5 +14,3 @@ delete_after_upload=True
speech_to_text = True speech_to_text = True
## The background image for the video. ## The background image for the video.
image_path = "img/blacksmall.jpg" image_path = "img/blacksmall.jpg"
## time to restart daily, "None" to disable
restart_time = "02:00"