diff --git a/src/functions.py b/src/functions.py index 3da2b2f..04173d8 100644 --- a/src/functions.py +++ b/src/functions.py @@ -4,8 +4,8 @@ load_dotenv(override=True) -logfile = os.getenv("LOGFILE", "log.log") -markfile = os.getenv("MARKFILE", "mark.log") +log_file = os.getenv("LOG_FILE", os.getenv("LOGFILE", "log.log")) +mark_file = os.getenv("MARK_FILE", os.getenv("MARKFILE", "mark.log")) def logger(message: str, log_type=0): @@ -32,14 +32,14 @@ def logger(message: str, log_type=0): if output is not None: print(output) - file = open(logfile, "a", encoding="utf-8") - file.write(output + "\n") + with open(f"{log_file}", "a", encoding="utf-8") as file: + file.write(output + "\n") def log_marked( username: str, library: str, movie_show: str, episode: str = None, duration=None ): - if markfile is None: + if mark_file is None: return output = f"{username}/{library}/{movie_show}" @@ -50,8 +50,8 @@ def log_marked( if duration: output += f"/{duration}" - file = open(f"{markfile}", "a", encoding="utf-8") - file.write(output + "\n") + with open(f"{mark_file}", "a", encoding="utf-8") as file: + file.write(output + "\n") # Reimplementation of distutils.util.strtobool due to it being deprecated diff --git a/src/main.py b/src/main.py index 0ee4b9c..3e6580b 100644 --- a/src/main.py +++ b/src/main.py @@ -262,10 +262,10 @@ def should_sync_server(server_1_type, server_2_type): def main_loop(): - logfile = os.getenv("LOGFILE", "log.log") - # Delete logfile if it exists - if os.path.exists(logfile): - os.remove(logfile) + log_file = os.getenv("LOG_FILE", os.getenv("LOGFILE", "log.log")) + # Delete log_file if it exists + if os.path.exists(log_file): + os.remove(log_file) dryrun = str_to_bool(os.getenv("DRYRUN", "False")) logger(f"Dryrun: {dryrun}", 1)