Compare commits
10 Commits
df637aa453
...
5b07fee6bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b07fee6bb | ||
|
|
5fce379744 | ||
|
|
9b5f10d118 | ||
|
|
7a1da4851c | ||
|
|
f0543c808f | ||
|
|
d2805ad091 | ||
|
|
a2b3b609f8 | ||
|
|
946c5b4112 | ||
|
|
747966e6db | ||
|
|
ef9f9cd5e3 |
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
|
|
@ -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
16
2024.ics
Normal 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
7
2024.json
Normal 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": []
|
||||
}
|
||||
4
Makefile
4
Makefile
|
|
@ -13,3 +13,7 @@ lint:
|
|||
|
||||
format:
|
||||
$(PYTHON) -m black -t py38 .
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(PYTHON) -m pytest
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
[](http://calver.org)
|
||||
[](https://codeclimate.com/github/NateScarlet/holiday-cn/maintainability)
|
||||
[](https://codeclimate.com/github/NateScarlet/holiday-cn/test_coverage)
|
||||

|
||||

|
||||
|
||||
中国法定节假日数据 自动每日抓取国务院公告
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
0
fetch_holidays.py → scripts/fetch.py
Executable file → Normal 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:
|
||||
|
|
@ -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
27
update.py → scripts/update.py
Executable file → Normal 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__":
|
||||
Loading…
Reference in New Issue
Block a user