Add logger, add looping

This commit is contained in:
Luigi311
2022-05-23 01:20:51 -06:00
parent 8b26e50346
commit 93da9eec34
4 changed files with 103 additions and 35 deletions

29
src/functions.py Normal file
View File

@@ -0,0 +1,29 @@
import os
from dotenv import load_dotenv
load_dotenv(override=True)
logfile = os.getenv("LOGFILE","log.log")
def logger(message, log_type=0):
output = str(message)
if log_type == 0:
pass
elif log_type == 1:
output = f"[INFO]: {output}"
elif log_type == 2:
output = f"[ERROR]: {output}"
else:
output = None
if output is not None:
print(output)
file = open(logfile, "a", encoding="utf-8")
file.write(output + "\n")
# Reimplementation of distutils.util.strtobool due to it being deprecated
# Source: https://github.com/PostHog/posthog/blob/01e184c29d2c10c43166f1d40a334abbc3f99d8a/posthog/utils.py#L668
def str_to_bool(value: any) -> bool:
if not value:
return False
return str(value).lower() in ("y", "yes", "t", "true", "on", "1")