feat: add json schema

resolve #23
This commit is contained in:
NateScarlet 2019-09-11 22:42:42 +08:00
parent 82dd7eed85
commit eefff066fa
No known key found for this signature in database
GPG Key ID: 5C242793B070309C
17 changed files with 73 additions and 8 deletions

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2007.json",
"year": 2007,
"papers": [
"http://www.gov.cn/zhengce/content/2008-03/28/content_1761.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2008.json",
"year": 2008,
"papers": [
"http://www.gov.cn/zhengce/content/2008-03/28/content_1645.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2009.json",
"year": 2009,
"papers": [
"http://www.gov.cn/zhengce/content/2008-12/10/content_1572.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2010.json",
"year": 2010,
"papers": [
"http://www.gov.cn/zhengce/content/2009-12/08/content_1476.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2011.json",
"year": 2011,
"papers": [
"http://www.gov.cn/zhengce/content/2010-12/10/content_1423.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2012.json",
"year": 2012,
"papers": [
"http://www.gov.cn/zhengce/content/2011-12/06/content_1411.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2013.json",
"year": 2013,
"papers": [
"http://www.gov.cn/zhengce/content/2012-12/10/content_1353.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2014.json",
"year": 2014,
"papers": [
"http://www.gov.cn/zhengce/content/2014-01/02/content_1194.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2015.json",
"year": 2015,
"papers": [
"http://www.gov.cn/zhengce/content/2014-12/16/content_9302.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2016.json",
"year": 2016,
"papers": [
"http://www.gov.cn/zhengce/content/2015-12/10/content_10394.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2017.json",
"year": 2017,
"papers": [
"http://www.gov.cn/zhengce/content/2016-12/01/content_5141603.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2018.json",
"year": 2018,
"papers": [
"http://www.gov.cn/zhengce/content/2017-11/30/content_5243579.htm"

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2019.json",
"year": 2019,
"papers": [
"http://www.gov.cn/zhengce/content/2018-12/06/content_5346276.htm",

View File

@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/2020.json",
"year": 2020,
"papers": [],
"days": []

View File

@ -9,9 +9,10 @@
- [x] 数据变化时时自动发布新版本 ( `Watch` - `Release only` 以获取邮件提醒! )
- [x] [发布页面]提供 JSON 打包下载
数据格式:
[JSON Schema](./schema.json)
```TypeScript
interface Holidays {
/** 完整年份, 整数。*/
@ -31,9 +32,9 @@ interface Holidays {
## 通过互联网使用
数据地址格式:
https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/{年份}.json
数据地址格式:
https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/{年份}.json
## 作为 git 子模块使用

27
schema.json Normal file
View File

@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json",
"type": "object",
"properties": {
"year": {
"type": "number",
"description": "年份"
},
"papers": {
"type": "array",
"items": { "type": "string" },
"description": "所用国务院文件网址列表"
},
"days": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string", "description": "节日名称" },
"date": { "type": "string", "description": "ISO 8601 日期" },
"isOffDay": { "type": "boolean", "description": "是否为休息日" }
}
}
}
}
}

View File

@ -48,10 +48,19 @@ def update_data(year: int) -> str:
filename = _file_path(f'{year}.json')
with open(filename, 'w', encoding='utf-8', newline='\n') as f:
json.dump(fetch_holiday(year), f,
indent=4,
ensure_ascii=False,
cls=CustomJSONEncoder)
data = fetch_holiday(year)
json.dump(
dict(
(('$schema',
'https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/schema.json'),
('$id',
f'https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/{year}.json'),
*data.items())),
f,
indent=4,
ensure_ascii=False,
cls=CustomJSONEncoder)
return filename