import json import os import yaml from pathlib import Path from typing import List from pydantic import BaseModel class Block(BaseModel): name: str keywords: List[str] def load(filename: str) -> List[Block]: result = [Block(path=filename, **block) for block in block_list] return result class Config(BaseModel): blackblocks: List[Block] whiteblocks: List[Block] check_delay: int = 1 minimize_delay: int = 5 blackblocks_only: bool = True class Config: extra = 'forbid' @classmethod def load(cls, config_file: str) -> Config: config_file = os.path.expanduser(config_file) with open(config_file, "r") as f: config_dict = yaml.safe_load(f) config = cls(**config_dict) return config