Spaces:
Sleeping
Sleeping
File size: 1,762 Bytes
14c1acb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Callable
@dataclass(frozen=True)
class SectionConfig:
key: str
title: str
source: str
content_type: str
settings_namespace: str
callbacks_namespace: str
enabled: bool = True
options: dict[str, Any] = field(default_factory=dict)
class SectionAdapter:
"""Common contract; each section has isolated configuration/state but shared infrastructure."""
def __init__(self, config: SectionConfig, pipeline, publisher=None):
self.config=config
self.pipeline=pipeline
self.publisher=publisher
def ingest(self, article: str, article_id: str, target=None):
return self.pipeline.ingest(
article=article,
article_id=f"{self.config.key}:{article_id}",
source=self.config.source,
target=target,
)
def process(self, payload: dict):
return self.pipeline.process(payload)
def status(self):
return {"section":self.config.key,"enabled":self.config.enabled,"options":dict(self.config.options)}
def set_option(self, name: str, value: Any):
opts=dict(self.config.options)
opts[name]=value
object.__setattr__(self.config,"options",opts)
# News and Sports are deliberately separate sections, while sharing the same capabilities.
NEWS = SectionConfig(
key="news", title="📰 الأخبار", source="news",
content_type="news", settings_namespace="news",
callbacks_namespace="news", options={}
)
SPORTS = SectionConfig(
key="sports", title="⚽ الرياضة", source="sports",
content_type="sports", settings_namespace="sports",
callbacks_namespace="sports", options={}
)
|