- 新增"查当周"按钮,计算当周周一至周日的加班总工时 - 新增 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>
34 lines
951 B
Python
34 lines
951 B
Python
import json
|
|
import subprocess
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# 年份:命令行参数 > 当前年份
|
|
if len(sys.argv) > 1:
|
|
year = int(sys.argv[1])
|
|
else:
|
|
year = datetime.now().year
|
|
|
|
# 读取现有数据
|
|
with open("data.json", "r", encoding="utf-8") as f:
|
|
a = json.load(f)
|
|
|
|
# 读取新年份数据
|
|
filename = f"holidays_{year}.json"
|
|
with open(filename, "r", encoding="utf-8") as f:
|
|
b = json.load(f)
|
|
|
|
# 去重:跳过 data.json 中已存在的日期
|
|
existing_dates = {item["date"] for item in a["list"]}
|
|
new_items = [item for item in b["data"]["list"] if item["date"] not in existing_dates]
|
|
a["list"].extend(new_items)
|
|
|
|
print(f"合并完成: 新增 {len(new_items)} 条记录,跳过 {len(b['data']['list']) - len(new_items)} 条重复")
|
|
|
|
# 保存 data.json
|
|
with open("data.json", "w", encoding="utf-8") as f:
|
|
json.dump(a, f, ensure_ascii=False, indent=2)
|
|
|
|
# 自动构建 main.js
|
|
subprocess.run(["python", "build.py"])
|