From 22bfb380111e5d11a47ea51c91832ec4b127e464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 22 Nov 2023 17:26:15 +0100 Subject: [PATCH] Fix decorator --- config.py | 17 +++++++++-------- main.py | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/config.py b/config.py index 14e1dc3..4841521 100644 --- a/config.py +++ b/config.py @@ -3,9 +3,9 @@ from typing import Dict import yaml import platformdirs -from pathlib import Path -from datetime import datetime, timezone +import datetime import dateutil.parser +from pathlib import Path import constants from log_setup import logger @@ -77,12 +77,14 @@ def create_db_config() -> None: def check_config_attr(func): - def wrapper(): + def wrapper(*args, **kwargs): try: - func() + return func(*args, **kwargs) except KeyError as e: logger.error("Missing config attribute:\n{}".format(e)) + return wrapper + class Config: def __init__(self, config: Dict): @@ -92,7 +94,6 @@ class Config: def player_base_rating(self) -> int: return self._config["player_base_rating"] - @check_config_attr def min_player_count(self) -> int: return self._config["min_player_count"] @@ -117,14 +118,14 @@ class Config: return self._config["ending_game_id"] @check_config_attr - def starting_time(self): + def starting_time(self) -> datetime.datetime: time = self._config["starting_time"] return dateutil.parser(time, tzinfos={'EST': 'US/Eastern'}) @check_config_attr - def ending_time(self): + def ending_time(self) -> datetime.datetime: time = self._config["ending_time"] - return dateutil.parser(time, tzinfos={'EST': 'US/Eastern'}) + return dateutil.parser.parse(time, tzinfos={'EST': 'US/Eastern'}) @check_config_attr def variant_base_rating(self, variant_name: str, player_count: int) -> int: diff --git a/main.py b/main.py index 59c3789..5eaf667 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import argparse +import datetime import verboselogs