fix: 兼容款式与套餐规格分组 (#166)
This commit is contained in:
@@ -8,7 +8,8 @@ XmlData = Union[str, bytes]
|
||||
Bounds = tuple[int, int, int, int]
|
||||
|
||||
_BOUNDS_PATTERN = re.compile(r"^\[(\d+),(\d+)\]\[(\d+),(\d+)\]$")
|
||||
_COLOR_HEADINGS = ("颜色分类", "颜色", "款式", "颜色款式")
|
||||
_COLOR_HEADINGS = ("颜色分类", "颜色", "款式", "颜色款式", "花色")
|
||||
_PACKAGE_HEADINGS = ("套餐",)
|
||||
|
||||
|
||||
def _parse_xml(xml_data: XmlData) -> ET.Element:
|
||||
@@ -91,6 +92,7 @@ def _screen_bounds(root: ET.Element) -> Optional[Bounds]:
|
||||
|
||||
def _heading_bounds(root: ET.Element) -> Optional[Bounds]:
|
||||
fuzzy_match: Optional[Bounds] = None
|
||||
package_fallback: Optional[Bounds] = None
|
||||
for node in root.iter("node"):
|
||||
text = node.get("text", "").strip()
|
||||
bounds = _parse_bounds(node.get("bounds", ""))
|
||||
@@ -102,7 +104,12 @@ def _heading_bounds(root: ET.Element) -> Optional[Bounds]:
|
||||
return bounds
|
||||
if fuzzy_match is None and any(heading in text for heading in _COLOR_HEADINGS):
|
||||
fuzzy_match = bounds
|
||||
return fuzzy_match
|
||||
if package_fallback is None and any(
|
||||
heading in text for heading in _PACKAGE_HEADINGS
|
||||
):
|
||||
package_fallback = bounds
|
||||
# “款式 + 套餐”优先定位款式;只有套餐一个维度时才用套餐兜底。
|
||||
return fuzzy_match or package_fallback
|
||||
|
||||
|
||||
def _target_scrollable_ancestor(
|
||||
|
||||
Reference in New Issue
Block a user