Skip to content

Commit

Permalink
增加 2024 年假期数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreace committed Oct 26, 2023
1 parent 5cae8e6 commit 400c29d
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 8 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

提供 HTTP 服务(Go)查询当前或指定日期是否为假日,返回中区分了假日、工作日。可以用于在特定日期类型完成自动化,比如使用 iOS 的快捷指令自动记录基金定投等。

提供脚本(Python)自动从 [中国政府官网](http://www.gov.cn/) 生成调休、补班数据。
提供脚本(Python)自动从 [中国政府官网](http://www.gov.cn/) 生成调休、补班数据。[生成假期 JSON 文件](#生成假期-json-文件) 提供了其他生成方式可供参考。

可以自行从 [Releases](https://github.com/Dreace/ChinaHolidayAPI/releases) 下载可执行文件并部署,或直接访问 [https://holiday.dreace.top](https://holiday.dreace.top) 查询假日。

目前可以查询 2023 至 2024 年的假期数据。

## 启动参数

| 短参数名 | 长参数名 | 类型 | 必填 | 说明 | 示例 |
Expand Down Expand Up @@ -56,10 +58,33 @@
}
```

## 生成假期 JSON 文件
要生成假期数据文件需要从官网复制带有标题的完整通知,如 [国务院办公厅关于2024年部分节假日安排的通知](https://www.gov.cn/zhengce/content/202310/content_6911527.htm)

### 使用 Python 脚本生成
复制通知全文粘贴到 `export_holiday.py` 中执行即可。

### 使用大语言模型(LLM)生成
可以使用 GPT-4 等大语言模型输入通知全文和参考格式快速生成假期数据,参考提示词(prompt)如下:
````text
步骤一:请分析下面使用 ````` 包裹的 2024 年放假数据
```
<通知全文>
```
步骤二:分析下面的使用 ```` 包裹的 2023 年已生成数据作为格式参考:
```
<参考数据,可以从直接粘贴往年的 JSON 文件内容>
```
生成要求如下:
1. 日期需要按升序排序
2. 严格按照参考格式生成
````
生成后请务必核对生成的数据是否准确,上面的提示词**仅在 GPT-4 中经过测试**可以生成准确的假期数据文件。

## 支持功能及未来计划

- [x] 脚本自动生成调休和补班 JSON 数据
- [x] 提供 HTTP 服务
- [ ] 支持查询历史年份假期
- [x] 支持查询历史年份假期
- [ ] 从命令行更新服务和优雅重启

138 changes: 138 additions & 0 deletions holidays/2023.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"2022-12-31": {
"type": "假日",
"note": "元旦"
},
"2023-01-01": {
"type": "假日",
"note": "元旦"
},
"2023-01-02": {
"type": "假日",
"note": "元旦"
},
"2023-01-21": {
"type": "假日",
"note": "春节"
},
"2023-01-22": {
"type": "假日",
"note": "春节"
},
"2023-01-23": {
"type": "假日",
"note": "春节"
},
"2023-01-24": {
"type": "假日",
"note": "春节"
},
"2023-01-25": {
"type": "假日",
"note": "春节"
},
"2023-01-26": {
"type": "假日",
"note": "春节"
},
"2023-01-27": {
"type": "假日",
"note": "春节"
},
"2023-01-28": {
"type": "补班日",
"note": "春节补班"
},
"2023-01-29": {
"type": "补班日",
"note": "春节补班"
},
"2023-04-05": {
"type": "假日",
"note": "清明节"
},
"2023-04-29": {
"type": "假日",
"note": "劳动节"
},
"2023-04-30": {
"type": "假日",
"note": "劳动节"
},
"2023-05-01": {
"type": "假日",
"note": "劳动节"
},
"2023-05-02": {
"type": "假日",
"note": "劳动节"
},
"2023-05-03": {
"type": "假日",
"note": "劳动节"
},
"2023-04-23": {
"type": "补班日",
"note": "劳动节补班"
},
"2023-05-06": {
"type": "补班日",
"note": "劳动节补班"
},
"2023-06-22": {
"type": "假日",
"note": "端午节"
},
"2023-06-23": {
"type": "假日",
"note": "端午节"
},
"2023-06-24": {
"type": "假日",
"note": "端午节"
},
"2023-06-25": {
"type": "补班日",
"note": "端午节补班"
},
"2023-09-29": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-09-30": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-01": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-02": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-03": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-04": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-05": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-06": {
"type": "假日",
"note": "中秋节、国庆节"
},
"2023-10-07": {
"type": "补班日",
"note": "中秋节、国庆节补班"
},
"2023-10-08": {
"type": "补班日",
"note": "中秋节、国庆节补班"
}
}
146 changes: 146 additions & 0 deletions holidays/2024.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"2024-01-01": {
"type": "假日",
"note": "元旦"
},
"2024-02-04": {
"type": "补班日",
"note": "春节补班"
},
"2024-02-10": {
"type": "假日",
"note": "春节"
},
"2024-02-11": {
"type": "假日",
"note": "春节"
},
"2024-02-12": {
"type": "假日",
"note": "春节"
},
"2024-02-13": {
"type": "假日",
"note": "春节"
},
"2024-02-14": {
"type": "假日",
"note": "春节"
},
"2024-02-15": {
"type": "假日",
"note": "春节"
},
"2024-02-16": {
"type": "假日",
"note": "春节"
},
"2024-02-17": {
"type": "假日",
"note": "春节"
},
"2024-02-18": {
"type": "补班日",
"note": "春节补班"
},
"2024-04-04": {
"type": "假日",
"note": "清明节"
},
"2024-04-05": {
"type": "假日",
"note": "清明节"
},
"2024-04-06": {
"type": "假日",
"note": "清明节"
},
"2024-04-07": {
"type": "补班日",
"note": "清明节补班"
},
"2024-04-28": {
"type": "补班日",
"note": "劳动节补班"
},
"2024-05-01": {
"type": "假日",
"note": "劳动节"
},
"2024-05-02": {
"type": "假日",
"note": "劳动节"
},
"2024-05-03": {
"type": "假日",
"note": "劳动节"
},
"2024-05-04": {
"type": "假日",
"note": "劳动节"
},
"2024-05-05": {
"type": "假日",
"note": "劳动节"
},
"2024-05-11": {
"type": "补班日",
"note": "劳动节补班"
},
"2024-06-10": {
"type": "假日",
"note": "端午节"
},
"2024-09-14": {
"type": "补班日",
"note": "中秋节补班"
},
"2024-09-15": {
"type": "假日",
"note": "中秋节"
},
"2024-09-16": {
"type": "假日",
"note": "中秋节"
},
"2024-09-17": {
"type": "假日",
"note": "中秋节"
},
"2024-09-29": {
"type": "补班日",
"note": "国庆节补班"
},
"2024-10-01": {
"type": "假日",
"note": "国庆节"
},
"2024-10-02": {
"type": "假日",
"note": "国庆节"
},
"2024-10-03": {
"type": "假日",
"note": "国庆节"
},
"2024-10-04": {
"type": "假日",
"note": "国庆节"
},
"2024-10-05": {
"type": "假日",
"note": "国庆节"
},
"2024-10-06": {
"type": "假日",
"note": "国庆节"
},
"2024-10-07": {
"type": "假日",
"note": "国庆节"
},
"2024-10-12": {
"type": "补班日",
"note": "国庆节补班"
}
}
34 changes: 28 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"embed"
_ "embed"
"encoding/json"
"fmt"
Expand All @@ -9,15 +10,15 @@ import (
"time"
)

//go:embed holiday.json
var holidayData []byte
//go:embed holidays/*.json
var holidayFiles embed.FS

type Holiday struct {
Type string `json:"type"`
Note string `json:"note"`
}

var holidays map[string]Holiday
var holidays = make(map[string]Holiday)

func isHoliday(date time.Time) (bool, string, string) {
dateString := date.Format("2006-01-02")
Expand Down Expand Up @@ -74,11 +75,32 @@ func main() {

pflag.Parse()

err := json.Unmarshal(holidayData, &holidays)
dirEntries, err := holidayFiles.ReadDir("holidays")
if err != nil {
output.Fatalf("%v", err)
return
panic(err)
}

// Iterate through the embedded files
for _, entry := range dirEntries {
if !entry.IsDir() && entry.Type().IsRegular() {
filePath := "holidays/" + entry.Name()
data, err := holidayFiles.ReadFile(filePath)
if err != nil {
panic(err)
}

var itemList map[string]Holiday
err = json.Unmarshal(data, &itemList)
if err != nil {
panic(err)
}

for k, v := range itemList {
holidays[k] = v
}
}
}

output.Printf("listen on http://%s:%d", host, port)
err = fasthttp.ListenAndServe(fmt.Sprintf("%s:%d", host, port), ShortColored(holidayHandler))
if err != nil {
Expand Down

0 comments on commit 400c29d

Please sign in to comment.