update search url of gov china

This commit is contained in:
Muhan Li 2023-06-21 23:57:37 +08:00
parent 3116bd140b
commit 855246e180
16 changed files with 101 additions and 47 deletions

View File

@ -50,11 +50,11 @@ jobs:
commit_message: update calendar data automatically
commit_user_name: Muhan Li
commit_user_email: limuhan@msn.com
commit_author: Muhan Li <limuhan@msn.com>
- name: Get last commit message
id: last-commit-message
run: |
echo "::set-output name=msg::$(git log -1 --pretty=%s)"
run: echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
- name: Update README
uses: stefanzweifel/git-auto-commit-action@v4

View File

@ -2,7 +2,7 @@
Subscription link of public holidays in mainland China
> Calendar data updated at 9:14 on June 21, 2023
> Calendar data updated at 8:01 on November 3, 2023
## Demo
@ -35,8 +35,8 @@ Subscription link of public holidays in mainland China
![overview](./docs/readme/overview.png)
## iOS 自动节假日闹钟
在周一至周五、调休补班日期自动打开标签内容包含「工作日闹钟」的闹钟
在周六、周日以及节假日假期自动关闭标签内容包含「工作日闹钟」的闹钟
[戳此](https://www.icloud.com/shortcuts/71ddab11837b408188821c3d992e8e4c) 下载 iOS 快捷指令脚本在「快捷指令」App 中设定一个每天凌晨运行的自动化任务吧~
[戳此](https://www.icloud.com/shortcuts/71ddab11837b408188821c3d992e8e4c) 导入 iOS 快捷指令脚本在「快捷指令」App 中设定一个每天凌晨运行的自动化任务吧~

28
crawler.http Normal file
View File

@ -0,0 +1,28 @@
POST https://sousuoht.www.gov.cn/athena/forward/2B22E8E39E850E17F95A016A74FCB6B673336FA8B6FEC0E2955907EF9AEE06BE
Content-Type: application/json;charset=UTF-8
Athenaappname: %E5%9B%BD%E7%BD%91%E6%90%9C%E7%B4%A2
Athenaappkey: R6kU1sKz%2BSHMWevvn8zRHAGJOwe6o53KEf7v0BJPVWY0Vxb4gIMCWDshQDWxw2Ua5CtSpEalXVlVzlj4mulMw6lnQzuqTEDDRC833wtXJyC%2F1kPbME1oCijkQOluRhbXZj3iRK1nXCzq5Sw%2F%2B2XbJbm%2BFEPLZRwoNNeYoOLcueg%3D
{
"code": "17da70961a7",
"historySearchWords": [
"节假日安排"
],
"dataTypeId": "107",
"orderBy": "time",
"searchBy": "title",
"appendixType": "",
"granularity": "ALL",
"trackTotalHits": true,
"beginDateTime": "",
"endDateTime": "",
"isSearchForced": 0,
"filters": [],
"pageNo": 1,
"pageSize": 10,
"customFilter": {
"operator": "and",
"properties": []
},
"searchWord": "节假日安排"
}

View File

@ -2,6 +2,7 @@
import os
import re
import json
from datetime import datetime, timezone, timedelta
from typing import Iterator, Tuple
@ -11,23 +12,23 @@ import requests
def main():
"""更新节假日信息"""
comments: list[str] = [
"// automatically generated by crawler.py",
"// manually checked by DATA NOT VERIFIED",
"// automatically generated on",
"// and manually checked on DATA NOT VERIFIED",
]
for year, link, holidays in data():
print(year, link, holidays, sep='\n')
file = f'./data/{year}.txt'
file = f"./data/{year}.txt"
if os.path.isfile(file):
with open(file, encoding='utf-8') as f_obj:
existing = f_obj.read()
if comments[0] in existing and comments[1] not in existing:
if "DATA NOT VERIFIED" not in existing:
continue # 数据已人工确认
with open(file, 'w', encoding='utf-8') as f_obj:
f_obj.write(
f"{comments[0]} ({beijing_time().strftime('%-m/%-d/%Y')})\n"
f"{comments[0]} {beijing_time().strftime('%-m/%-d/%Y')}\n"
f"{comments[1]}\n// source: {link}\n\n{holidays}"
)
@ -53,10 +54,10 @@ def data() -> Iterator[Tuple[str, str, str]]:
response.encoding = response.apparent_encoding
line_regex = r"(?P<id>.)、(?P<name>.*)(</.*?>)?(?P<detail>.*放假.*。)"
for line in response.text.replace('<br/>', '\n').split('\n'):
for line in response.text.replace('<br/>', '\n').replace('</p>', '\n').split('\n'):
if match := re.search(line_regex, line):
work, rest, *_ = match.group('detail').split('')
dates = ';'.join((match.group('name'), parse(work), parse(rest)))
work, rest, *_ = match.group("detail").split('')
dates = ';'.join((match.group("name"), parse(work), parse(rest)))
print(dates) # 已知需要人工干预如下情况: 1.与周末连休, 2.补休
results.append(f"{dates:30} // {match.group('detail')}")
@ -93,13 +94,38 @@ def parse(text: str) -> str:
def source() -> Iterator[Tuple[str, str]]:
"""获取官网发布通知列表"""
search_url = "http://sousuo.gov.cn/s.htm?t=paper&advance=false&n=&codeYear=&codeCode=" \
"&searchfield=title&sort=&q=%E8%8A%82%E5%81%87%E6%97%A5%E5%AE%89%E6%8E%92"
link_regex = r"href=['\"](?P<link>.*?)['\"].*国务院办公厅关于(?P<year>20\d\d)年.*通知"
search_url = ("https://sousuoht.www.gov.cn/athena/forward/"
"2B22E8E39E850E17F95A016A74FCB6B673336FA8B6FEC0E2955907EF9AEE06BE")
search_resp = requests.post(
search_url,
timeout=(5, 10),
json={
"code": "17da70961a7",
"dataTypeId": "107",
"orderBy": "time",
"searchBy": "title",
"pageNo": 1,
"pageSize": 10,
"searchWord": "节假日安排"
},
headers={
"Content-Type": "application/json;charset=UTF-8",
"Athenaappname": "%E5%9B%BD%E7%BD%91%E6%90%9C%E7%B4%A2", # 国网搜索
"Athenaappkey": "R6kU1sKz%2BSHMWevvn8zRHAGJOwe6o53KEf7v0BJPVWY0Vxb4gIMCWDshQDW"
"xw2Ua5CtSpEalXVlVzlj4mulMw6lnQzuqTEDDRC833wtXJyC%2F1kPbME1oCi"
"jkQOluRhbXZj3iRK1nXCzq5Sw%2F%2B2XbJbm%2BFEPLZRwoNNeYoOLcueg%3D"
},
)
for line in requests.get(search_url, timeout=(5, 10)).text.split('\n'):
if match := re.search(link_regex, line):
yield match.group('year'), match.group('link')
search_resp.encoding = search_resp.apparent_encoding
search_data = json.loads(search_resp.text)
# print(search_data)
for result in search_data["result"]["data"]["middle"]["list"]:
if match := re.search(r"^国务院办公厅关于(?P<year>20\d\d)年.*通知", result["title"]):
print(match.group("year"), result["url"])
print(result, end="\n\n")
yield match.group("year"), result["url"]
def beijing_time() -> datetime:

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (4/10/2022)
// manually checked by @bugstop (4/11/2022)
// automatically generated on 4/10/2022
// and manually checked on 4/11/2022
// source: http://www.gov.cn/zhengce/content/2012-12/10/content_1353.htm
元旦;1.1-1.3;1.5,1.6 // 1月1日至3日放假调休共3天。1月5日(星期六)、1月6日(星期日)上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (4/10/2022)
// manually checked by @bugstop (4/11/2022)
// automatically generated on 4/10/2022
// and manually checked on 4/11/2022
// source: http://www.gov.cn/zhengce/content/2014-01/02/content_1194.htm
元旦;1.1; // 1月1日放假1天。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (4/10/2022)
// manually checked by @bugstop (4/11/2022)
// automatically generated on 4/10/2022
// and manually checked on 4/11/2022
// source: http://www.gov.cn/zhengce/content/2014-12/16/content_9302.htm
元旦;1.1-1.3;1.4 // 1月1日至3日放假调休共3天。1月4日星期日上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (4/10/2022)
// manually checked by @bugstop (4/11/2022)
// automatically generated on 4/10/2022
// and manually checked on 4/11/2022
// source: http://www.gov.cn/zhengce/content/2015-12/10/content_10394.htm
元旦;1.1-1.3; // 1月1日放假与周末连休。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (4/10/2022)
// manually checked by @bugstop (4/11/2022)
// automatically generated on 4/10/2022
// and manually checked on 4/11/2022
// source: http://www.gov.cn/zhengce/content/2016-12/01/content_5141603.htm
元旦;0.1-1.2; // 1月1日放假1月2日星期一补休。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (3/27/2022)
// manually checked by @bugstop (3/27/2022)
// automatically generated on 3/27/2022
// and manually checked on 3/27/2022
// source: http://www.gov.cn/zhengce/content/2017-11/30/content_5243579.htm
元旦;0.2-1.1; // 1月1日放假与周末连休。
@ -8,4 +8,4 @@
劳动节;4.29-5.1;4.28 // 4月29日至5月1日放假调休共3天。4月28日星期六上班。
端午节;6.16-6.18; // 6月18日放假与周末连休。
中秋节;9.22-9.24; // 9月24日放假与周末连休。
国庆节;10.1-10.7;9.29,9.30 // 10月1日至7日放假调休共7天。9月29日星期六、9月30日星期日上班。
国庆节;10.1-10.7;9.29,9.30 // 10月1日至7日放假调休共7天。9月29日星期六、9月30日星期日上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (3/27/2022)
// manually checked by @bugstop (3/27/2022)
// automatically generated on 3/27/2022
// and manually checked on 3/27/2022
// source: http://www.gov.cn/zhengce/content/2018-12/06/content_5346276.htm
元旦;0.2-1.1;0.3 // 2018年12月30日至2019年1月1日放假调休共3天。2018年12月29日星期六上班。
@ -8,4 +8,4 @@
劳动节;5.1; // 5月1日放假。
端午节;6.7-6.9; // 6月7日放假与周末连休。
中秋节;9.13-9.15; // 9月13日放假与周末连休。
国庆节;10.1-10.7;9.29,10.12 // 10月1日至7日放假调休共7天。9月29日星期日、10月12日星期六上班。
国庆节;10.1-10.7;9.29,10.12 // 10月1日至7日放假调休共7天。9月29日星期日、10月12日星期六上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (3/27/2022)
// manually checked by @bugstop (3/27/2022)
// automatically generated on 3/27/2022
// and manually checked on 3/27/2022
// source: http://www.gov.cn/zhengce/content/2019-11/21/content_5454164.htm
元旦;1.1; // 2020年1月1日放假共1天。
@ -7,4 +7,4 @@
清明节;4.4-4.6; // 4月4日至6日放假调休共3天。
劳动节;5.1-5.5;4.26,5.9 // 5月1日至5日放假调休共5天。4月26日星期日、5月9日星期六上班。
端午节;6.25-6.27;6.28 // 6月25日至27日放假调休共3天。6月28日星期日上班。
国庆节、中秋节;10.1-10.8;9.27,10.10 // 10月1日至8日放假调休共8天。9月27日星期日、10月10日星期六上班。
国庆节、中秋节;10.1-10.8;9.27,10.10 // 10月1日至8日放假调休共8天。9月27日星期日、10月10日星期六上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (3/27/2022)
// manually checked by @bugstop (3/27/2022)
// automatically generated on 3/27/2022
// and manually checked on 3/27/2022
// source: http://www.gov.cn/zhengce/content/2020-11/25/content_5564127.htm
元旦;1.1-1.3; // 2021年1月1日至3日放假共3天。
@ -8,4 +8,4 @@
劳动节;5.1-5.5;4.25,5.8 // 5月1日至5日放假调休共5天。4月25日星期日、5月8日星期六上班。
端午节;6.12-6.14; // 6月12日至14日放假共3天。
中秋节;9.19-9.21;9.18 // 9月19日至21日放假调休共3天。9月18日星期六上班。
国庆节;10.1-10.7;9.26,10.9 // 10月1日至7日放假调休共7天。9月26日星期日、10月9日星期六上班。
国庆节;10.1-10.7;9.26,10.9 // 10月1日至7日放假调休共7天。9月26日星期日、10月9日星期六上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (3/27/2022)
// manually checked by @bugstop (3/27/2022)
// automatically generated on 3/27/2022
// and manually checked on 3/27/2022
// source: http://www.gov.cn/zhengce/content/2021-10/25/content_5644835.htm
元旦;1.1-1.3; // 2022年1月1日至3日放假共3天。
@ -8,4 +8,4 @@
劳动节;4.30-5.4;4.24,5.7 // 4月30日至5月4日放假调休共5天。4月24日星期日、5月7日星期六上班。
端午节;6.3-6.5; // 6月3日至5日放假共3天。
中秋节;9.10-9.12; // 9月10日至12日放假共3天。
国庆节;10.1-10.7;10.8,10.9 // 10月1日至7日放假调休共7天。10月8日星期六、10月9日星期日上班。
国庆节;10.1-10.7;10.8,10.9 // 10月1日至7日放假调休共7天。10月8日星期六、10月9日星期日上班。

View File

@ -1,5 +1,5 @@
// automatically generated by crawler.py (12/11/2022)
// manually checked by @bugstop (12/27/2022)
// automatically generated on 12/11/2022
// and manually checked on 12/27/2022
// source: http://www.gov.cn/zhengce/content/2022-12/08/content_5730844.htm
元旦;0.1-1.2; // 2022年12月31日至2023年1月2日放假调休共3天。

View File

@ -1 +1 @@
requests~=2.27.1
requests~=2.28.1