From 400c29d7263e5ffef10fea26b2384449554a4f4e Mon Sep 17 00:00:00 2001 From: "dreace@foxmail.com" Date: Thu, 26 Oct 2023 23:05:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=202024=20=E5=B9=B4=E5=81=87?= =?UTF-8?q?=E6=9C=9F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 29 ++++++++- holidays/2023.json | 138 ++++++++++++++++++++++++++++++++++++++++++ holidays/2024.json | 146 +++++++++++++++++++++++++++++++++++++++++++++ main.go | 34 +++++++++-- 4 files changed, 339 insertions(+), 8 deletions(-) create mode 100644 holidays/2023.json create mode 100644 holidays/2024.json diff --git a/README.md b/README.md index 0cf089f..b69758f 100644 --- a/README.md +++ b/README.md @@ -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 年的假期数据。 + ## 启动参数 | 短参数名 | 长参数名 | 类型 | 必填 | 说明 | 示例 | @@ -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] 支持查询历史年份假期 - [ ] 从命令行更新服务和优雅重启 diff --git a/holidays/2023.json b/holidays/2023.json new file mode 100644 index 0000000..920ead5 --- /dev/null +++ b/holidays/2023.json @@ -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": "中秋节、国庆节补班" + } +} \ No newline at end of file diff --git a/holidays/2024.json b/holidays/2024.json new file mode 100644 index 0000000..3de7ce4 --- /dev/null +++ b/holidays/2024.json @@ -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": "国庆节补班" + } +} diff --git a/main.go b/main.go index 4cc1180..61e1e4a 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "embed" _ "embed" "encoding/json" "fmt" @@ -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") @@ -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 {