fix: parse names and ids in bulk input

This commit is contained in:
nyan404 committed 2026-08-25 03:19:41 +03:00
1 parent ba844c5e4e
commit a2aacf4503
2 files changed
+23 -4

No files matched your search

+10 -4
View File
@@ -245,7 +245,7 @@ def parse_natural_bulk(text: str) -> tuple[dict[str, Any], list[str]] | None:
lowered = text.lower()
if re.search(r"\b(урок|тренировк)\w*\b", lowered):
people_text = re.sub(r"(?i)^\s*(?:урок|тренировк\w*)\s*", "", text)
people = [(match.group("name").strip(" |,–-"), int(match.group("id")))
people = [(match.group("name").strip(" |,–-[]"), int(match.group("id")))
for match in _NATURAL_PERSON_RE.finditer(people_text)]
fields: dict[str, Any] = {"mode": "training"}
questions: list[str] = []
@@ -295,9 +295,15 @@ def parse_natural_bulk(text: str) -> tuple[dict[str, Any], list[str]] | None:
return fields, questions
date_match = _DATE_RE.search(text)
times = _TIME_RE.findall(text)
person_tail = text[max((match.end() for match in _TIME_RE.finditer(text)), default=0):]
people = [(match.group("name").strip(" |,–-"), int(match.group("id")))
for match in _NATURAL_PERSON_RE.finditer(person_tail)]
person_source = _DATE_RE.sub(" ", text)
person_source = _TIME_RE.sub(" ", person_source)
person_source = re.sub(
r"(?i)\b(?:лу|лазание|зу|зоркость|самостоятельно|самостоятельный|несамостоятельно|несамостоятельный|сам|несам)\b",
" ",
person_source,
)
people = [(match.group("name").strip(" |,–-[]"), int(match.group("id")))
for match in _NATURAL_PERSON_RE.finditer(person_source)]
if not date_match and len(times) < 2 and len(people) < 1:
return None
skill_match = re.search(r"(?i)\b(лу|лазание|зу|зоркость)\b", text)