Compare commits

...

10 Commits

Author SHA1 Message Date
renovate[bot]
5b07fee6bb chore(deps): update dependency pytest to v7.2.1 2023-01-14 15:36:10 +00:00
renovate[bot]
5fce379744 chore(deps): update dependency requests to v2.28.2 2023-01-12 20:57:47 +00:00
NateScarlet
9b5f10d118
docs: update stale badge
[skip ci]
2023-01-03 12:42:12 +08:00
GitHub Actions
7a1da4851c chore(release): update holiday data
[skip ci]
2023-01-01 12:12:54 +00:00
renovate[bot]
f0543c808f chore(deps): update dependency black to v22.12.0 2022-12-09 19:38:03 +00:00
NateScarlet
d2805ad091
revert: chore(release): update holiday data
This reverts commit 747966e6db.
2022-12-09 20:47:21 +08:00
NateScarlet
a2b3b609f8
chore: run formatter 2022-12-09 19:12:25 +08:00
NateScarlet
946c5b4112
chore: update path in scripts 2022-12-09 17:42:01 +08:00
GitHub Actions
747966e6db chore(release): update holiday data
[skip ci]
2022-12-09 08:53:54 +00:00
NateScarlet
ef9f9cd5e3
chore: move python code to /scripts 2022-12-09 16:52:02 +08:00
15 changed files with 55 additions and 116 deletions

View File

@ -16,7 +16,7 @@ jobs:
with:
python-version: '3.8'
- name: Install dependencies
run: pip install -r requirements.txt -r dev-requirements.txt
run: pip install -r dev-requirements.txt
- name: Setup git user
run: |
git config user.name "GitHub Actions"
@ -29,10 +29,10 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request' }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: coverage run -a ./update.py --release
run: coverage run -a ./scripts/update.py --release
- name: Update
if: ${{ !(github.ref == 'refs/heads/master' && github.event_name != 'pull_request') }}
run: coverage run -a ./update.py
run: coverage run -a ./scripts/update.py
# FIXME
#- name: Report coverage
# env:

16
2024.ics Normal file
View File

@ -0,0 +1,16 @@
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
CLASS:PUBLIC
X-WR-CALDESC:中国法定节假日数据,自动每日抓取国务院公
告。
X-WR-CALNAME:中国法定节假日
BEGIN:VTIMEZONE
TZID:Asia/Shanghai
BEGIN:STANDARD
DTSTART;VALUE=DATE-TIME:19700101T000000
TZOFFSETFROM:+0800
TZOFFSETTO:+0800
END:STANDARD
END:VTIMEZONE
END:VCALENDAR

7
2024.json Normal file
View File

@ -0,0 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2024.json",
"year": 2024,
"papers": [],
"days": []
}

View File

@ -13,3 +13,7 @@ lint:
format:
$(PYTHON) -m black -t py38 .
.PHONY: test
test:
$(PYTHON) -m pytest

View File

@ -5,7 +5,7 @@
[![CalVer](https://img.shields.io/badge/calver-YYYY.0M.0D-22bfda.svg)](http://calver.org)
[![Maintainability](https://api.codeclimate.com/v1/badges/c8e9d9c51bd2d858c577/maintainability)](https://codeclimate.com/github/NateScarlet/holiday-cn/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c8e9d9c51bd2d858c577/test_coverage)](https://codeclimate.com/github/NateScarlet/holiday-cn/test_coverage)
![Maintenance](https://img.shields.io/maintenance/yes/2022.svg)
![Maintenance](https://img.shields.io/maintenance/yes/2023.svg)
中国法定节假日数据 自动每日抓取国务院公告

View File

@ -1,3 +1,10 @@
pytest==7.2.0
# main
requests==2.28.2
beautifulsoup4==4.11.1
tqdm==4.64.1
icalendar==4.1.0
# test
pytest==7.2.1
coverage==6.5.0
black==22.10.0
black==22.12.0

View File

@ -14,90 +14,6 @@ TZOFFSETTO:+0800
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
SUMMARY:元旦假期
DTSTART;VALUE=DATE:20180101
DTEND;VALUE=DATE:20180102
DTSTAMP;VALUE=DATE:20180101
UID:2018-01-01/2018-01-02/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:上班(补春节假期)
DTSTART;VALUE=DATE:20180211
DTEND;VALUE=DATE:20180212
DTSTAMP;VALUE=DATE:20180211
UID:2018-02-11/2018-02-12/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:春节假期
DTSTART;VALUE=DATE:20180215
DTEND;VALUE=DATE:20180222
DTSTAMP;VALUE=DATE:20180215
UID:2018-02-15/2018-02-22/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:上班(补春节假期)
DTSTART;VALUE=DATE:20180224
DTEND;VALUE=DATE:20180225
DTSTAMP;VALUE=DATE:20180224
UID:2018-02-24/2018-02-25/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:清明节假期
DTSTART;VALUE=DATE:20180405
DTEND;VALUE=DATE:20180408
DTSTAMP;VALUE=DATE:20180405
UID:2018-04-05/2018-04-08/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:上班(补清明节假期)
DTSTART;VALUE=DATE:20180408
DTEND;VALUE=DATE:20180409
DTSTAMP;VALUE=DATE:20180408
UID:2018-04-08/2018-04-09/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:上班(补劳动节假期)
DTSTART;VALUE=DATE:20180428
DTEND;VALUE=DATE:20180429
DTSTAMP;VALUE=DATE:20180428
UID:2018-04-28/2018-04-29/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:劳动节假期
DTSTART;VALUE=DATE:20180429
DTEND;VALUE=DATE:20180502
DTSTAMP;VALUE=DATE:20180429
UID:2018-04-29/2018-05-02/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:端午节假期
DTSTART;VALUE=DATE:20180618
DTEND;VALUE=DATE:20180619
DTSTAMP;VALUE=DATE:20180618
UID:2018-06-18/2018-06-19/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:中秋节假期
DTSTART;VALUE=DATE:20180924
DTEND;VALUE=DATE:20180925
DTSTAMP;VALUE=DATE:20180924
UID:2018-09-24/2018-09-25/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:上班(补国庆节假期)
DTSTART;VALUE=DATE:20180929
DTEND;VALUE=DATE:20181001
DTSTAMP;VALUE=DATE:20180929
UID:2018-09-29/2018-10-01/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:国庆节假期
DTSTART;VALUE=DATE:20181001
DTEND;VALUE=DATE:20181008
DTSTAMP;VALUE=DATE:20181001
UID:2018-10-01/2018-10-08/NateScarlet/holiday-cn
END:VEVENT
BEGIN:VEVENT
SUMMARY:上班(补元旦假期)
DTSTART;VALUE=DATE:20181229
DTEND;VALUE=DATE:20181230

View File

@ -1,4 +0,0 @@
requests==2.28.1
beautifulsoup4==4.11.1
tqdm==4.64.1
icalendar==4.1.0

0
fetch_holidays.py → scripts/fetch.py Executable file → Normal file
View File

View File

@ -3,7 +3,7 @@ import json
import pytest
from fetch_holidays import (
from fetch import (
CustomJSONEncoder,
DescriptionParser,
get_paper,
@ -11,7 +11,7 @@ from fetch_holidays import (
get_rules,
)
from .filetools import _file_path
from filetools import workspace_path
def test_get_paper_urls():
@ -40,7 +40,7 @@ def _normalize(iterable):
def _description_parsing_cases():
with open(
_file_path("description_parsing_cases.json"),
workspace_path("scripts", "description_parsing_cases.json"),
"r",
encoding="utf-8",
) as f:

View File

@ -5,6 +5,6 @@ import os
__dirname__ = os.path.abspath(os.path.dirname(__file__))
def _file_path(*other):
def workspace_path(*other):
return os.path.abspath(os.path.join(__dirname__, *other))
return os.path.join(os.path.dirname(__dirname__), *other)

27
update.py → scripts/update.py Executable file → Normal file
View File

@ -13,8 +13,9 @@ from zipfile import ZipFile
from tqdm import tqdm
from fetch_holidays import CustomJSONEncoder, fetch_holiday
from fetch import CustomJSONEncoder, fetch_holiday
from generate_ics import generate_ics
from filetools import workspace_path
class ChinaTimezone(tzinfo):
@ -30,19 +31,11 @@ class ChinaTimezone(tzinfo):
return timedelta()
__dirname__ = os.path.abspath(os.path.dirname(__file__))
def _file_path(*other):
return os.path.join(__dirname__, *other)
def update_data(year: int) -> Iterator[str]:
"""Update and store data for a year."""
json_filename = _file_path(f"{year}.json")
ics_filename = _file_path(f"{year}.ics")
json_filename = workspace_path(f"{year}.json")
ics_filename = workspace_path(f"{year}.ics")
with open(json_filename, "w", encoding="utf-8", newline="\n") as f:
data = fetch_holiday(year)
@ -74,14 +67,14 @@ def update_data(year: int) -> Iterator[str]:
def update_main_ics(fr_year, to_year):
all_days = []
for year in range(fr_year, to_year + 1):
filename = _file_path(f"{year}.json")
filename = workspace_path(f"{year}.json")
if not os.path.isfile(filename):
continue
with open(filename, "r", encoding="utf8") as inf:
data = json.loads(inf.read())
all_days.extend(data.get("days"))
filename = _file_path("holiday-cn.ics")
filename = workspace_path("holiday-cn.ics")
generate_ics(
all_days,
filename,
@ -147,8 +140,8 @@ def main():
temp_note_fd, temp_note_name = mkstemp()
with open(temp_note_fd, "w", encoding="utf-8") as f:
f.write(tag + "\n\n```diff\n" + diff + "\n```\n")
os.makedirs(_file_path("dist"), exist_ok=True)
zip_path = _file_path("dist", f"holiday-cn-{tag}.zip")
os.makedirs(workspace_path("dist"), exist_ok=True)
zip_path = workspace_path("dist", f"holiday-cn-{tag}.zip")
pack_data(zip_path)
subprocess.run(
@ -171,10 +164,10 @@ def pack_data(file):
"""Pack data json in zip file."""
zip_file = ZipFile(file, "w")
for i in os.listdir(__dirname__):
for i in os.listdir(workspace_path()):
if not re.match(r"\d+\.json", i):
continue
zip_file.write(_file_path(i), i)
zip_file.write(workspace_path(i), i)
if __name__ == "__main__":

View File