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

57 lines
1.4 KiB
Python

#!/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_KEY = "BALDI_PLUS_EXECUTABLE_PATH"
EXEC_PATH = environ.get(EXEC_KEY, 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 "
f"{EXEC_KEY}, 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