diff options
Diffstat (limited to 'scrapers/registry.py')
| -rw-r--r-- | scrapers/registry.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/scrapers/registry.py b/scrapers/registry.py new file mode 100644 index 0000000..6d9bde6 --- /dev/null +++ b/scrapers/registry.py @@ -0,0 +1,22 @@ +from __future__ import annotations +from typing import Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from scrapers.base import NewsSource + +_registry: dict[str, type["NewsSource"]] = {} + + +def register(url_key: str): + def decorator(cls): + _registry[url_key] = cls + return cls + return decorator + + +def get_source(url_key: str) -> Optional[type["NewsSource"]]: + return _registry.get(url_key) + + +def get_all() -> dict[str, type["NewsSource"]]: + return dict(_registry) |
