parent
6613c1d25b
commit
d84dabea44
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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日(星期六)上班。",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user