Przeglądaj źródła

feat: add json schema

resolve #23
NateScarlet 6 lat temu
rodzic
commit
eefff066fa
17 zmienionych plików z 73 dodań i 8 usunięć
  1. 2 0
      2007.json
  2. 2 0
      2008.json
  3. 2 0
      2009.json
  4. 2 0
      2010.json
  5. 2 0
      2011.json
  6. 2 0
      2012.json
  7. 2 0
      2013.json
  8. 2 0
      2014.json
  9. 2 0
      2015.json
  10. 2 0
      2016.json
  11. 2 0
      2017.json
  12. 2 0
      2018.json
  13. 2 0
      2019.json
  14. 2 0
      2020.json
  15. 5 4
      README.md
  16. 27 0
      schema.json
  17. 13 4
      update.py

+ 2 - 0
2007.json

@@ -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"

+ 2 - 0
2008.json

@@ -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"

+ 2 - 0
2009.json

@@ -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"

+ 2 - 0
2010.json

@@ -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"

+ 2 - 0
2011.json

@@ -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"

+ 2 - 0
2012.json

@@ -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"

+ 2 - 0
2013.json

@@ -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"

+ 2 - 0
2014.json

@@ -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"

+ 2 - 0
2015.json

@@ -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"

+ 2 - 0
2016.json

@@ -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"

+ 2 - 0
2017.json

@@ -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"

+ 2 - 0
2018.json

@@ -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"

+ 2 - 0
2019.json

@@ -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",

+ 2 - 0
2020.json

@@ -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": []

+ 5 - 4
README.md

@@ -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 - 0
schema.json

@@ -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": "是否为休息日" }
+        }
+      }
+    }
+  }
+}

+ 13 - 4
update.py

@@ -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