mirror of
https://github.com/majmongoose/PageBot.git
synced 2024-12-04 01:53:24 -05:00
parent
45b65fc6fe
commit
8b00d683d6
39
pagebot.py
39
pagebot.py
@ -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()
|
||||||
|
if process.returncode != 0:
|
||||||
|
print("TTD has crashed. Relaunching...")
|
||||||
|
else:
|
||||||
|
print("TTD has exited normally.")
|
||||||
|
break
|
||||||
|
|
||||||
while True:
|
# Wait for a few seconds before relaunching
|
||||||
# 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
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
## initialize watchdogs
|
## initialize watchdogs
|
||||||
|
@ -13,6 +13,4 @@ delete_after_upload=True
|
|||||||
## This will slow down pages and is unreliable.
|
## This will slow down pages and is unreliable.
|
||||||
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"
|
|
Loading…
Reference in New Issue
Block a user