scripts/git_release_notify.py
Ching 2e2bbac18d feat(git_release_notify.py): 定时检查某个 repo 的 release 有没有更新版本,通过 bark 进行通知
定时检查某个 repo 的 release 有没有更新版本,通过 bark 进行通知

Signed-off-by: Ching <loooching@gmail.com>
2023-03-21 11:02:56 +08:00

72 lines
1.8 KiB
Python

import json
import requests
import time
# 要查询的 GitHub 项目名称列表
project_names = ["project-name-1", "project-name-2", "project-name-3"]
# 存储项目最新版本号的字典
version_dict = {}
# Bark 推送接口 URL
# bark_url = "https://api.day.app/yourkey"
bark_url = "http://bark.tunpok.com/UZ6zC82bKRjQaXiVkosVWh"
# 版本号保存文件路径
version_file_path = "versions.json"
def load_versions():
global version_dict
try:
with open(version_file_path, "r") as f:
version_dict = json.load(f)
except FileNotFoundError:
pass
def save_versions():
with open(version_file_path, "w") as f:
json.dump(version_dict, f)
def check_version():
for project_name in project_names:
# 构造 API 请求 URL
url = f"https://api.github.com/repos/{project_name}/releases/latest"
# url = f'https://api.github.com/repos/Chanzhaoyu/chatgpt-web/releases/latest'
# 发送请求并解析响应
response = requests.get(url)
data = response.json()
# 提取当前版本号
current_version = data["tag_name"]
# 更新版本号
if version_dict.get(project_name) != current_version:
version_dict[project_name] = current_version
send_notification(project_name, current_version)
# 保存版本号到本地文件
save_versions()
def send_notification(project_name, current_version):
# 发送 HTTP GET 请求到 Bark 推送接口
title = f"New version of {project_name} released"
content = f"Version: {current_version}"
url = f"{bark_url}/{title}/{content}"
response = requests.get(url)
print(response.text)
if __name__ == '__main__':
load_versions()
while True:
check_version()
# 每小时检查一次
time.sleep(3600)