diff --git a/scripts/description_parsing_cases.json b/scripts/description_parsing_cases.json index 5f88a12..bc7e5d6 100644 --- a/scripts/description_parsing_cases.json +++ b/scripts/description_parsing_cases.json @@ -1,4 +1,9 @@ [ + { + "year": 2024, + "description": "1月1日(周三)放假1天,不调休", + "expected": [{ "date": "2024-01-01", "isOffDay": true }] + }, { "year": 2019, "description": "2018年12月30日至2019年1月1日放假调休,共3天。2018年12月29日(星期六)上班。", diff --git a/scripts/fetch.py b/scripts/fetch.py index 8dd6ae0..1a9c1c5 100644 --- a/scripts/fetch.py +++ b/scripts/fetch.py @@ -277,7 +277,7 @@ def get_date(self, year: Optional[int], month: Optional[int], day: int) -> date: class SentenceParser: """Parser for holiday shift description sentence.""" - def __init__(self, parent: DescriptionParser, sentence): + def __init__(self, parent: DescriptionParser, sentence: str): self.parent = parent self.sentence = sentence @@ -316,7 +316,8 @@ def _extract_dates_1(self, value: str) -> Iterator[date]: def _extract_dates_2(self, value: str) -> Iterator[date]: value = re.sub(r"(.+?)", "", value) match = re.findall( - r"(?:(\d+)年)?(?:(\d+)月)?(\d+)日(?:至|-|—)(?:(\d+)年)?(?:(\d+)月)?(\d+)日", value + r"(?:(\d+)年)?(?:(\d+)月)?(\d+)日(?:至|-|—)(?:(\d+)年)?(?:(\d+)月)?(\d+)日", + value, ) for groups in match: groups = [_cast_int(i) for i in groups] @@ -357,6 +358,8 @@ def parse(self) -> Iterator[dict]: yield i def _parse_rest_1(self): + if self.sentence.startswith("不"): + return match = re.match(r"(.+)(放假|补休|调休|公休)+(?:\d+天)?$", self.sentence) if match: for i in self.extract_dates(match.group(1)):