Added logger.

This commit is contained in:
2025-07-22 15:35:37 +02:00
parent afe3cecb4f
commit d4ed76e153
5 changed files with 88 additions and 34 deletions

View File

@@ -2,10 +2,13 @@
import argparse
from . import database
from .logger_setup import get_logger
# We can't reuse load_subreddits from main anymore if it's not in the same file
# So we will duplicate it here. It's small and keeps this script self-contained.
import json
log = get_logger()
def load_subreddits(filepath):
"""Loads a list of subreddits from a JSON file."""
try:
@@ -13,7 +16,7 @@ def load_subreddits(filepath):
data = json.load(f)
return data.get("subreddits", [])
except (FileNotFoundError, json.JSONDecodeError) as e:
print(f"Error loading config file '{filepath}': {e}")
log.error(f"Error loading config file '{filepath}': {e}")
return None
def run_cleanup():
@@ -52,17 +55,17 @@ def run_cleanup():
run_any_task = True
# If --all is used, default to 'subreddits.json' if --subreddits wasn't also specified
config_file = args.subreddits or 'subreddits.json'
print(f"\nCleaning subreddits based on active list in: {config_file}")
log.info(f"\nCleaning subreddits based on active list in: {config_file}")
active_subreddits = load_subreddits(config_file)
if active_subreddits is not None:
database.clean_stale_subreddits(active_subreddits)
if not run_any_task:
parser.print_help()
print("\nError: Please provide at least one cleanup option (e.g., --tickers, --subreddits, --all).")
log.error("\nError: Please provide at least one cleanup option (e.g., --tickers, --subreddits, --all).")
return
print("\nCleanup finished.")
log.info("\nCleanup finished.")
if __name__ == "__main__":
run_cleanup()