diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 704b2f9..6720a80 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -4,6 +4,12 @@ on: push: branches: - v2 + paths-ignore: + - '**.md' + - '.github/**' + - 'list.json' + - 'telegram_update.py' + - 'update_list.py' jobs: build: @@ -23,13 +29,23 @@ jobs: # 安装依赖 - name: Install dependencies run: | - mkdir tmp && cd tmp python -m pip install --upgrade pip pip install httpx # 发送通知 - name: Send notice run: | - cd tmp - cp ../telegram_update.py ./ python telegram_update.py ${{ secrets.TG_BOT_TOKEN }} + + # 更新 list + - name: Update list + run: | + python update_list.py + + # Auto commit + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + # Optional. Commit message for the created commit. + # Defaults to "Apply automatic changes" + commit_message: "CI: Update version json" + file_pattern: 'list.json' diff --git a/telegram_update.py b/telegram_update.py index 759f21a..7dd03f8 100644 --- a/telegram_update.py +++ b/telegram_update.py @@ -1,8 +1,10 @@ -import json, time, sys +import time +import sys +import contextlib from httpx import get, post token = str(sys.argv[1]) -main = json.loads(get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").content) +main = get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").json() text = ( ( ( @@ -19,17 +21,10 @@ text = ( + '): ' ) + main['commit']['message'] -push_content = {'chat_id': '-1001441461877', 'disable_web_page_preview': 'True', 'parse_mode': 'markdown', - 'text': text} url = f'https://api.telegram.org/bot{token}/sendMessage' -try: - main_req = post(url, data=push_content) -except: - pass -push_content['chat_id'] = '-1001319957857' -time.sleep(1) -try: - main_req = post(url, data=push_content) -except: - pass +for cid in ['-1001441461877', '-1001319957857']: + push_content = {'chat_id': cid, 'disable_web_page_preview': 'True', 'parse_mode': 'markdown', 'text': text} + with contextlib.suppress(Exception): + main_req = post(url, data=push_content) + time.sleep(1) print(main['sha'] + " ok!") diff --git a/update_list.py b/update_list.py new file mode 100644 index 0000000..0ee2e38 --- /dev/null +++ b/update_list.py @@ -0,0 +1,29 @@ +import json +import os +from httpx import get + +main = get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").json() +plugins = [i["filename"].split("/")[0] for i in main["files"] if "/main.py" in i["filename"]] +with open("list.json", "r", encoding="utf8") as f: + list_json = json.load(f) +for plugin in plugins: + exist = False + for plug_dict in list_json["list"]: + if plug_dict["name"] == plugin: + exist = True + old_version = float(plug_dict["version"]) + list_json["list"][list_json["list"].index(plug_dict)]["version"] = str(old_version + 0.01) + break + if not exist: + list_json["list"].append( + {"name": plugin, + "version": "1.0", + "section": "chat", + "maintainer": main['commit']['author']['name'], + "size": f"{os.path.getsize(f'{plugin}{os.sep}main.py') / 1000} kb", + "supported": True, + "des-short": "这个人很懒,什么都没留下", + "des": "这个人很懒,什么都没有留下。"}) +with open("list.json", "w", encoding="utf8") as f: + json.dump(list_json, f, ensure_ascii=False, indent=4) +print(main['sha'] + " ok!")