Fix decorator
This commit is contained in:
parent
ab32fae4f2
commit
22bfb38011
2 changed files with 10 additions and 8 deletions
17
config.py
17
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:
|
||||
|
|
1
main.py
1
main.py
|
@ -1,4 +1,5 @@
|
|||
import argparse
|
||||
import datetime
|
||||
|
||||
import verboselogs
|
||||
|
||||
|
|
Loading…
Reference in a new issue