From cb2f6866ddc1cecb0dd18adf918529876a76b874 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Fri, 15 Apr 2022 01:00:13 +0100 Subject: [PATCH] Ensure paths work on *Nix & Windows --- exclamation_mark_charity/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/exclamation_mark_charity/__init__.py b/exclamation_mark_charity/__init__.py index 0e09845..c66639f 100644 --- a/exclamation_mark_charity/__init__.py +++ b/exclamation_mark_charity/__init__.py @@ -1,5 +1,6 @@ import logging import os +from pathlib import Path from dotenv import load_dotenv @@ -9,10 +10,14 @@ load_dotenv() # Constants BOT_TOKEN = os.environ.get("BOT_TOKEN") BOT_PREFIX = "!" +DB_FILE = Path("db", "charity.db") +DB_FILE.parent.mkdir(parents=True, exist_ok=True) +LOG_FILE = Path("logs", "discord.log") +LOG_FILE.parent.mkdir(parents=True, exist_ok=True) # Set Up Logging -logger = logging.getLogger('discord') -logger.setLevel(logging.DEBUG) -handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w') -handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) -logger.addHandler(handler) +LOGGER = logging.getLogger("discord") +LOGGER.setLevel(logging.DEBUG) +handler = logging.FileHandler(filename=LOG_FILE, encoding="utf-8", mode="w") +handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) +LOGGER.addHandler(handler)