Prepare mobile de parser release

This commit is contained in:
qananasikq
2026-04-27 21:10:17 +03:00
parent 31f87a9bdf
commit b86bcd04b8
21 changed files with 2835 additions and 423 deletions

View File

@@ -275,11 +275,104 @@ class RuntimeFiltersConfig:
return not self.exclude.matches(values)
@dataclass(slots=True)
class RuntimeMobileDeSegment:
make: str | None = None
make_id: str | None = None
model: str | None = None
model_id: str | None = None
search_url: str | None = None
only_new: bool | None = None
price_min: str | None = None
price_max: str | None = None
year_min: str | None = None
year_max: str | None = None
start_page: int = 1
max_pages: int | None = None
label: str | None = None
@classmethod
def from_dict(cls, data: dict[str, Any] | None) -> "RuntimeMobileDeSegment | None":
data = data or {}
make = str(data.get("make") or "").strip() or None
make_id = str(data.get("make_id") or data.get("makeId") or "").strip() or None
model = str(data.get("model") or "").strip() or None
model_id = str(data.get("model_id") or data.get("modelId") or "").strip() or None
search_url = str(data.get("search_url") or data.get("searchUrl") or data.get("listing_url") or "").strip() or None
if not make_id and not make and not search_url:
return None
label = str(data.get("label") or "").strip() or None
return cls(
make=make,
make_id=make_id,
model=model,
model_id=model_id,
search_url=search_url,
only_new=_optional_bool(data.get("only_new")),
price_min=str(data.get("price_min") or "").strip() or None,
price_max=str(data.get("price_max") or "").strip() or None,
year_min=str(data.get("year_min") or "").strip() or None,
year_max=str(data.get("year_max") or "").strip() or None,
start_page=max(1, _optional_int(data.get("start_page")) or 1),
max_pages=_optional_int(data.get("max_pages")),
label=label,
)
def to_task_kwargs(self) -> dict[str, Any]:
return {
"make": self.make,
"make_id": self.make_id,
"model": self.model,
"model_id": self.model_id,
"search_url": self.search_url,
"only_new": self.only_new,
"price_min": self.price_min,
"price_max": self.price_max,
"year_min": self.year_min,
"year_max": self.year_max,
"start_page": self.start_page,
"max_pages": self.max_pages,
"label": self.label or self.display_name,
}
@property
def display_name(self) -> str:
if self.label:
return self.label
if self.search_url:
return "filtered-url"
parts = [part for part in [self.make, self.model] if part]
return " / ".join(parts) or self.make_id or "mobilede-segment"
@dataclass(slots=True)
class RuntimeMobileDeConfig:
segments: tuple[RuntimeMobileDeSegment, ...] = ()
@classmethod
def from_dict(cls, data: dict[str, Any] | None) -> "RuntimeMobileDeConfig":
data = data or {}
raw_segments = data.get("segments")
segments: list[RuntimeMobileDeSegment] = []
if isinstance(raw_segments, list):
for item in raw_segments:
if not isinstance(item, dict):
continue
segment = RuntimeMobileDeSegment.from_dict(item)
if segment is not None:
segments.append(segment)
return cls(segments=tuple(segments))
def is_empty(self) -> bool:
return not self.segments
@dataclass(slots=True)
class RuntimeConfig:
sync: RuntimeSyncConfig = field(default_factory=RuntimeSyncConfig)
listing: RuntimeListingConfig = field(default_factory=RuntimeListingConfig)
filters: RuntimeFiltersConfig = field(default_factory=RuntimeFiltersConfig)
mobilede: RuntimeMobileDeConfig = field(default_factory=RuntimeMobileDeConfig)
@classmethod
def from_file(cls, config_path: str | None) -> "RuntimeConfig":
@@ -298,4 +391,5 @@ class RuntimeConfig:
sync=RuntimeSyncConfig.from_dict(payload.get("sync")),
listing=RuntimeListingConfig.from_dict(payload.get("listing")),
filters=RuntimeFiltersConfig.from_dict(payload.get("filters")),
mobilede=RuntimeMobileDeConfig.from_dict(payload.get("mobilede")),
)