1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-09-19 05:45:36 +05:30

add BB_plus_watch_temp_files.py

This commit is contained in:
Intel A80486DX2-66 2024-07-03 19:33:48 +03:00
parent 5a785bfd9f
commit bb5a4c0a64
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -0,0 +1,55 @@
#!/usr/bin/python3
# BB_plus_watch_temp_files.py
#
# Watch for any new files created by Baldi's Basics Plus
#
# The video game Baldi's Basics Plus is created by Basically Games
#
# Author: Intel A80486DX2-66
# License: Unlicense
from dotenv import load_dotenv
from os import environ, listdir, makedirs
from os.path import exists, join as path_join
from subprocess import Popen
from tempfile import gettempdir
from time import sleep
from sys import exit
if exists(".env"):
load_dotenv()
EXEC_PATH = environ.get("BBIEAL_EXECUTABLE_PATH", None)
PATH_TO_WATCH = path_join(gettempdir(),
"Basically Games", "Baldi's Basics Plus")
def respectful_makedirs(path: str) -> None:
if not exists(path):
makedirs(path)
if __name__ == "__main__":
if EXEC_PATH is None:
print("Please create a .env file in the current directory with key "
"BBIEAL_EXECUTABLE_PATH, containing path to the executable of "
"your copy of the video game Baldi's Basics Plus, or set such an "
"environmental variable.")
exit(1)
print("Path to watch:", PATH_TO_WATCH)
respectful_makedirs(PATH_TO_WATCH)
print("Starting the game", flush=True)
handle = Popen([EXEC_PATH])
print("Watching directory")
files = set(listdir(PATH_TO_WATCH))
while handle.poll() is None:
sleep(1)
new_files = set(listdir(PATH_TO_WATCH)) - files
if new_files:
for f in new_files:
print("[+]", f)
files |= new_files