aboutsummaryrefslogtreecommitdiffstats
path: root/scrapers/registry.py
blob: 6d9bde61b121cb40643b6167d709d24728dc6bbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage