diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py index 6c56b4c..b6e6b8b 100644 --- a/discord_rss_bot/main.py +++ b/discord_rss_bot/main.py @@ -55,6 +55,8 @@ def add( @app.command() def stats() -> None: """Print the number of feeds and entries in the database""" + app_dir = typer.get_app_dir(Settings.APP_NAME) + typer.echo(app_dir) with closing(make_reader(Settings.db_file)) as reader: feed_count = reader.get_feed_counts() entry_count = reader.get_entry_counts() @@ -100,14 +102,14 @@ def check() -> None: @app.command() def backup() -> None: """Backup the database""" - backup_dir = os.path.join(Settings.data_dir, "backup") + backup_dir = os.path.join(Settings.app_dir, "backup") os.makedirs(backup_dir, exist_ok=True) # Get the current time current_time = time.strftime("%Y-%m-%d_%H-%M-%S") backup_file_location = os.path.join( - Settings.data_dir, "backup", f"db_{current_time}.sqlite" + Settings.app_dir, "backup", f"db_{current_time}.sqlite" ) copyfile(Settings.db_file, backup_file_location) diff --git a/discord_rss_bot/settings.py b/discord_rss_bot/settings.py index aaec826..3ba7b78 100644 --- a/discord_rss_bot/settings.py +++ b/discord_rss_bot/settings.py @@ -1,25 +1,24 @@ import configparser import os import sys +from pathlib import Path -from platformdirs import user_data_dir +import typer class Settings: - data_dir = user_data_dir( - appname="discord-rss-bot", # The name of application. - appauthor="TheLovinator", # The name of the app author or distributing body for this application - roaming=True, # Whether to use the roaming appdata directory on Windows - ) + APP_NAME: str = "discord-rss-bot" + + app_dir = typer.get_app_dir(APP_NAME) # Create the data directory if it doesn't exist - os.makedirs(data_dir, exist_ok=True) + os.makedirs(app_dir, exist_ok=True) # Store the database file in the data directory - db_file = os.path.join(data_dir, "db.sqlite") + db_file: Path = Path(os.path.join(app_dir, "db.sqlite")) # Store the config in the data directory - config_location = os.path.join(data_dir, "config.conf") + config_location: Path = Path(os.path.join(app_dir, "config.conf")) if not os.path.isfile(config_location): # TODO: Add config for db_file and config_location diff --git a/poetry.lock b/poetry.lock index aec87e1..85911e1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -323,7 +323,7 @@ python-versions = ">=2.6" name = "platformdirs" version = "2.4.0" description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "main" +category = "dev" optional = false python-versions = ">=3.6" @@ -570,7 +570,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "bfc980afa624bed7398f84e92bbe8a08724b12a0e5e9d40ed7fd3d6ec24d4b30" +content-hash = "d31a61ac43f00272d9a36098174ebd7bc781c2c4abff929326b322fd5030ab39" [metadata.files] aiohttp = [ diff --git a/pyproject.toml b/pyproject.toml index 4f26751..a3f517d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ python = "^3.9" reader = "^2.6" typer = {extras = ["all"], version = "^0.4.0"} dhooks = "^1.1.4" -platformdirs = "^2.4.0" [tool.poetry.dev-dependencies] pytest = "^5.2"