From 2e2bbac18d5eaa287b121398ce12b9d54ab1af82 Mon Sep 17 00:00:00 2001 From: Ching Date: Tue, 21 Mar 2023 11:02:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(git=5Frelease=5Fnotify.py):=20=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E6=A3=80=E6=9F=A5=E6=9F=90=E4=B8=AA=20repo=20?= =?UTF-8?q?=E7=9A=84=20release=20=E6=9C=89=E6=B2=A1=E6=9C=89=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=EF=BC=8C=E9=80=9A=E8=BF=87=20bark?= =?UTF-8?q?=20=E8=BF=9B=E8=A1=8C=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 定时检查某个 repo 的 release 有没有更新版本,通过 bark 进行通知 Signed-off-by: Ching --- git_release_notify.py | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 git_release_notify.py diff --git a/git_release_notify.py b/git_release_notify.py new file mode 100644 index 0000000..c5e01d4 --- /dev/null +++ b/git_release_notify.py @@ -0,0 +1,71 @@ +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) + +