Skip to content

Commit

Permalink
fix: handle new description
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Nov 12, 2024
1 parent aefd2f1 commit a7a1065
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions scripts/description_parsing_cases.json
Original file line number Diff line number Diff line change
@@ -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日(星期六)上班。",
Expand Down
7 changes: 5 additions & 2 deletions scripts/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)):
Expand Down

1 comment on commit a7a1065

@KwokRoot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.