fix: handle 2020-02 patch rule

fix #50
This commit is contained in:
NateScarlet 2020-02-08 16:52:45 +08:00
parent 6613c1d25b
commit d84dabea44
No known key found for this signature in database
GPG Key ID: 5C242793B070309C
2 changed files with 22 additions and 3 deletions

View File

@ -115,7 +115,7 @@ def get_patch_rules(lines: Iterator[str]) -> Iterator[Tuple[str, str]]:
"""
name = None
for i in lines:
match = re.match(r'.*\d+年(.{2,})(?:假期|放假)安排.*', i)
match = re.match(r'.*\d+年([^和、]{2,})(?:假期|放假).*安排', i)
if match:
name = match.group(1)
if not name:
@ -187,6 +187,13 @@ class DescriptionParser:
class SentenceParser:
"""Parser for holiday shift description sentence. """
special_cases = {
'延长2020年春节假期至2月2日农历正月初九': [
{"date": date(2020, 2, 1), "isOffDay": True},
{"date": date(2020, 2, 2), "isOffDay": True},
],
}
def __init__(self, parent: DescriptionParser, sentence):
self.parent = parent
self.sentence = sentence
@ -260,7 +267,6 @@ class SentenceParser:
Returns:
Iterator[dict]: Days without name field.
"""
for method in self.parsing_methods:
for i in method(self):
yield i
@ -297,10 +303,15 @@ class SentenceParser:
'isOffDay': True
}
def _parse_special(self):
for i in self.special_cases.get(self.sentence, []):
yield i
parsing_methods = [
_parse_rest_1,
_parse_work_1,
_parse_shift_1,
_parse_special,
]
@ -330,7 +341,6 @@ def fetch_holiday(year: int):
"""Fetch holiday data. """
papers = get_paper_urls(year)
papers.reverse()
days = dict()

View File

@ -1,4 +1,13 @@
[
{
"year": 2020,
"description": "延长2020年春节假期至2月2日农历正月初九星期日2月3日星期一起正常上班。",
"expected": [
{ "date": "2020-02-01", "isOffDay": true },
{ "date": "2020-02-02", "isOffDay": true },
{ "date": "2020-02-03", "isOffDay": false }
]
},
{
"year": 2019,
"description": "2018年12月30日至2019年1月1日放假调休共3天。2018年12月29日星期六上班。",