Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: wxread

concurrency:
group: ${{ github.workflow }} # 使用工作流名称作为并发组的key
cancel-in-progress: true # 取消任何正在进行的相同并发组的工作流

on:
schedule:
# 凌晨任务:北京时间每天 01:00(UTC 前一天 17:00)
- cron: '0 17 * * *'
#- cron: '0 17 * * *'
# 早间任务:北京时间每天 05:00(UTC 前一天 21:00)
#- cron: '0 21 * * *'
# 午间任务:北京时间每天 11:40(UTC 03:40
#- cron: '40 3 * * *'
# 午间任务:北京时间每天 11:00(UTC 03:00
- cron: '00 3 * * *'
# 晚间任务:北京时间每天 22:00(UTC 14:00)
#- cron: '0 14 * * *'
workflow_dispatch: # 手动触发
Expand Down Expand Up @@ -45,7 +49,19 @@ jobs:
WXPUSHER_SPT: ${{ secrets.WXPUSHER_SPT }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
SERVERCHAN_SPT: ${{ secrets.SERVERCHAN_SPT }}
READ_NUM: ${{ vars.READ_NUM }} # 使用 Repository Variables
FEISHU_WEBHOOK: ${{ secrets.FEISHU_WEBHOOK }}

run: |
python main.py

keepalive-job:
name: Keepalive Workflow
if: ${{ always() }}
needs: deploy
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: liskin/gh-workflow-keepalive@v1.2.1
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
TELEGRAM_CHAT_ID = "" or os.getenv("TELEGRAM_CHAT_ID")
# wxpusher推送时需填
WXPUSHER_SPT = "" or os.getenv("WXPUSHER_SPT")
# 飞书通知webhook
FEISHU_WEBHOOK = "" or os.getenv("FEISHU_WEBHOOK")
# read接口的bash命令,本地部署时可对应替换headers、cookies
curl_str = os.getenv('WXREAD_CURL_BASH')

Expand Down
29 changes: 28 additions & 1 deletion push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import requests
import logging
from config import PUSHPLUS_TOKEN, TELEGRAM_CHAT_ID, TELEGRAM_BOT_TOKEN, WXPUSHER_SPT
from config import PUSHPLUS_TOKEN, TELEGRAM_CHAT_ID, TELEGRAM_BOT_TOKEN, WXPUSHER_SPT, FEISHU_WEBHOOK

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,6 +87,31 @@ def push_wxpusher(self, content, spt):
logger.info("将在 %d 秒后重试...", sleep_time)
time.sleep(sleep_time)

def push_feishu(self, content, webhook_url):
"""飞书消息推送"""
payload = {
"msg_type": "text",
"content": {"text": content}
}
attempts = 5
for attempt in range(attempts):
try:
response = requests.post(
webhook_url,
headers={"Content-Type": "application/json"},
data=json.dumps(payload).encode('utf-8'),
timeout=10
)
response.raise_for_status()
logger.info("✅ 飞书响应: %s", response.text)
break
except requests.exceptions.RequestException as e:
logger.error("❌ 飞书推送失败: %s", e)
if attempt < attempts - 1:
sleep_time = random.randint(180, 360)
logger.info("将在 %d 秒后重试...", sleep_time)
time.sleep(sleep_time)


"""外部调用"""

Expand All @@ -104,5 +129,7 @@ def push(content, method):
return notifier.push_telegram(content, bot_token, chat_id)
elif method == "wxpusher":
return notifier.push_wxpusher(content, WXPUSHER_SPT)
elif method == "feishu":
return notifier.push_feishu(content, FEISHU_WEBHOOK)
else:
raise ValueError("❌ 无效的通知渠道,请选择 'pushplus'、'telegram' 或 'wxpusher'")