From 6230af0aecfab62d35ab4cc161559681fd2c319f Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 12 Aug 2020 13:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20=E4=BD=BF=E7=94=A8=20CI=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8F=91=E9=80=81=E6=9B=B4=E6=96=B0=E5=88=B0?= =?UTF-8?q?=20Tg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/python.yml | 28 ++++++++++++++++++++++++++++ telegram_update.py | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/python.yml create mode 100644 telegram_update.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..a6f823a --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,28 @@ +name: Github commit to telegram + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + # 此步骤使用 GitHub 的 https://github.com/actions/checkout + - name: checkout actions + uses: actions/checkout@v1 + + # 设置python环境 + # 此步骤使用 GitHub 的 https://github.com/actions/setup-python + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + + # 安装依赖 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install requests + + # 发送通知 + - name: Send notice + run: python telegram_update.py ${{ secrets.TG_BOT_TOKEN }} \ No newline at end of file diff --git a/telegram_update.py b/telegram_update.py new file mode 100644 index 0000000..9b5d37c --- /dev/null +++ b/telegram_update.py @@ -0,0 +1,27 @@ +import json, time, sys +from requests import get, post + +token = str(sys.argv[1]) + +time.sleep(30) +main = json.loads(get("https://api.github.com/repos/xtaodada/PagerMaid_Plugins/commits/master").content) +push_content = {} +push_content['chat_id'] = '-1001441461877' +push_content['disable_web_page_preview'] = 'True' +push_content['parse_mode'] = 'markdown' +push_content['text'] = "#更新日志 #" + main['commit']['author'][ + 'name'] + ' \n\n🔨 [' + main['sha'][0:7] + '](https://github.com/xtaodada/PagerMaid_Plugins/compare/' + \ + main[ + 'sha'] + '): ' + main['commit']['message'] +url = '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 = get(url, data=push_content) +except: + pass +print(main['sha'] + " ok!")