Răsfoiți Sursa

feat: add json schema

resolve #23
NateScarlet 6 ani Ʈn urmă
părinte
comite
eefff066fa
17 a modificat fișierele cu 73 adăugiri și 8 ștergeri
  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