Compare commits

..

No commits in common. "5b07fee6bb0a045371c24add3b2c6b6a179ab56c" and "df637aa45373671b1e71e6dff6817b885d404e4f" have entirely different histories.

15 changed files with 116 additions and 55 deletions

View File

@ -16,7 +16,7 @@ jobs:
with:
python-version: '3.8'
- name: Install dependencies
run: pip install -r dev-requirements.txt
run: pip install -r requirements.txt -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 ./scripts/update.py --release
run: coverage run -a ./update.py --release
- name: Update
if: ${{ !(github.ref == 'refs/heads/master' && github.event_name != 'pull_request') }}
run: coverage run -a ./scripts/update.py
run: coverage run -a ./update.py
# FIXME
#- name: Report coverage
# env:

View File

@ -1,16 +0,0 @@
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

View File

@ -1,7 +0,0 @@
{
"$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,7 +13,3 @@ 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/2023.svg)
![Maintenance](https://img.shields.io/maintenance/yes/2022.svg)
中国法定节假日数据 自动每日抓取国务院公告

View File

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

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

View File

@ -14,6 +14,90 @@ 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

4
requirements.txt Normal file
View File

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

0
tests/__init__.py Normal file
View File

View File

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

View File

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

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

@ -13,9 +13,8 @@ from zipfile import ZipFile
from tqdm import tqdm
from fetch import CustomJSONEncoder, fetch_holiday
from fetch_holidays import CustomJSONEncoder, fetch_holiday
from generate_ics import generate_ics
from filetools import workspace_path
class ChinaTimezone(tzinfo):
@ -31,11 +30,19 @@ 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 = workspace_path(f"{year}.json")
ics_filename = workspace_path(f"{year}.ics")
json_filename = _file_path(f"{year}.json")
ics_filename = _file_path(f"{year}.ics")
with open(json_filename, "w", encoding="utf-8", newline="\n") as f:
data = fetch_holiday(year)
@ -67,14 +74,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 = workspace_path(f"{year}.json")
filename = _file_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 = workspace_path("holiday-cn.ics")
filename = _file_path("holiday-cn.ics")
generate_ics(
all_days,
filename,
@ -140,8 +147,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(workspace_path("dist"), exist_ok=True)
zip_path = workspace_path("dist", f"holiday-cn-{tag}.zip")
os.makedirs(_file_path("dist"), exist_ok=True)
zip_path = _file_path("dist", f"holiday-cn-{tag}.zip")
pack_data(zip_path)
subprocess.run(
@ -164,10 +171,10 @@ def pack_data(file):
"""Pack data json in zip file."""
zip_file = ZipFile(file, "w")
for i in os.listdir(workspace_path()):
for i in os.listdir(__dirname__):
if not re.match(r"\d+\.json", i):
continue
zip_file.write(workspace_path(i), i)
zip_file.write(_file_path(i), i)
if __name__ == "__main__":