增加自动更新data.json的脚本
This commit is contained in:
17
comp_json.py
Normal file
17
comp_json.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
# 读取 A 和 B 文件
|
||||||
|
with open("data.json", "r", encoding="utf-8") as f:
|
||||||
|
a = json.load(f)
|
||||||
|
|
||||||
|
with open("holidays_2026.json", "r", encoding="utf-8") as f:
|
||||||
|
b = json.load(f)
|
||||||
|
|
||||||
|
# 假设 list 在 data.list 下(根据你之前的接口结构)
|
||||||
|
a["list"].extend(b["data"]["list"])
|
||||||
|
|
||||||
|
# 保存合并结果
|
||||||
|
with open("merged.json", "w", encoding="utf-8") as f:
|
||||||
|
json.dump(a, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
print("✅ 合并完成!结果已保存到 merged.json")
|
||||||
7311
holidays_2026.json
Normal file
7311
holidays_2026.json
Normal file
File diff suppressed because it is too large
Load Diff
32
update.py
Normal file
32
update.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
# 接口地址(建议加上你的 api_key,否则可能无法访问)
|
||||||
|
url = "https://api.apihubs.cn/holiday/get"
|
||||||
|
params = {
|
||||||
|
"year": 2026,
|
||||||
|
"page": 1,
|
||||||
|
"size": 370
|
||||||
|
# "api_key": "your_api_key_here" # ⚠️ 如果接口坞要求认证,请取消注释并填入你的 key
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url, params=params)
|
||||||
|
response.raise_for_status() # 检查 HTTP 错误
|
||||||
|
|
||||||
|
# 解析 JSON 数据
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
# 保存到文件
|
||||||
|
with open("holidays_2026.json", "w", encoding="utf-8") as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
print("✅ 数据已成功保存到 holidays_2026.json")
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"❌ 网络请求失败: {e}")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
print("❌ 返回内容不是有效的 JSON 格式")
|
||||||
|
print("原始响应:", response.text)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ 发生未知错误: {e}")
|
||||||
Reference in New Issue
Block a user