Files
FM-OHS/update.py
fengbh b74978d2dc 新增查当周按钮,代码重构与数据分离
- 新增"查当周"按钮,计算当周周一至周日的加班总工时
- 新增 createQueryButton 工厂函数,消除月按钮重复代码
- 修复 calculateTimeDifference 返回字符串导致 NaN 的 bug
- 修复 sumOfSecondColumn/get_work_time 缺少空值保护的 bug
- 修复 isWorkDay 中 == 改为 ===
- var 统一为 const/let,提取 QUERY_DELAY_MS 常量
- 提取 getCustomMonthRange 中重复的 formatLocal
- 按钮增加 cursor:pointer 样式
- 数据与代码分离:main.template.js(~300行)+ build.py 自动组装 main.js
- update.py/comp_json.py 支持命令行年份参数,默认当年
- comp_json.py 增加去重逻辑
- 更新 README 为 GitHub 开源项目风格,含快速上手和每年更新章节

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 19:11:13 +08:00

39 lines
996 B
Python

import requests
import json
import sys
from datetime import datetime
# 年份:命令行参数 > 当前年份
if len(sys.argv) > 1:
year = int(sys.argv[1])
else:
year = datetime.now().year
url = "https://api.apihubs.cn/holiday/get"
params = {
"year": year,
"page": 1,
"size": 370
# "api_key": "your_api_key_here" # 如果接口要求认证,请取消注释并填入你的 key
}
try:
response = requests.get(url, params=params)
response.raise_for_status()
data = response.json()
filename = f"holidays_{year}.json"
with open(filename, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f"数据已成功保存到 {filename}")
except requests.exceptions.RequestException as e:
print(f"网络请求失败: {e}")
except json.JSONDecodeError:
print("返回内容不是有效的 JSON 格式")
print("原始响应:", response.text)
except Exception as e:
print(f"发生未知错误: {e}")