Auto Update News #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Update News | |
on: | |
schedule: | |
- cron: "30 22 * * *" | |
workflow_dispatch: | |
jobs: | |
update-news: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js environment | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install axios | |
run: npm install axios | |
- name: Fetch and format news content | |
id: fetch_news | |
run: | | |
echo "Fetching news content..." | |
raw_content=$(curl -s -m 10 "https://api.03c3.cn/api/zb?type=text") | |
formatted_content=$(echo "$raw_content" | sed 's/$/\n/g') | |
formatted_content="${formatted_content}\n\n![图片](https://api.03c3.cn/api/zb)" | |
echo -e "$formatted_content" > DailyNews.md | |
echo "Formatted content saved to DailyNews.md" | |
echo "FORMATTED_CONTENT<<EOF" >> $GITHUB_ENV | |
echo "$formatted_content" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Commit changes to DailyNews.md | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add DailyNews.md | |
git commit -m "《每天60秒读懂世界》新闻存档" || echo "No changes to commit" | |
continue-on-error: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push changes | |
run: | | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set environment variables | |
run: | | |
echo "Setting environment variables..." | |
echo "PUSHPLUS_TOKEN=${{ secrets.PUSHPLUS_TOKEN }}" >> $GITHUB_ENV | |
echo "SERVERCHAN_SCKEY=${{ secrets.SERVERCHAN_SCKEY }}" >> $GITHUB_ENV | |
echo "WECHAT_BOT_URL=${{ secrets.WECHAT_BOT_URL }}" >> $GITHUB_ENV | |
- name: Send news content via Pushplus | |
run: | | |
if [ -n "${{ env.PUSHPLUS_TOKEN }}" ]; then | |
node -e " | |
const axios = require('axios'); | |
const content = \`${{ env.FORMATTED_CONTENT }}\`; | |
const TOKEN = '${{ env.PUSHPLUS_TOKEN }}'; | |
axios.post('http://www.pushplus.plus/send/', { | |
token: TOKEN, | |
title: '每天60秒读懂世界', | |
content: content, | |
template: 'markdown' | |
}).then(response => { | |
console.log(response.data.msg || 'Pushplus 推送成功'); | |
}).catch(error => { | |
console.error('Pushplus 推送失败: ' + error); | |
process.exit(1); | |
}); | |
" | |
fi | |
- name: Send news content via ServerChan | |
run: | | |
if [ -n "${{ env.SERVERCHAN_SCKEY }}" ]; then | |
node -e " | |
const axios = require('axios'); | |
const content = \`${{ env.FORMATTED_CONTENT }}\`; | |
const SCKEY = '${{ env.SERVERCHAN_SCKEY }}'; | |
axios.post(\`https://sctapi.ftqq.com/${SCKEY}.send\`, { | |
title: '每天60秒读懂世界', | |
desp: content | |
}).then(response => { | |
console.log(response.data.msg || 'Server酱 推送成功'); | |
}).catch(error => { | |
console.error('Server酱 推送失败: ' + error); | |
process.exit(1); | |
}); | |
" | |
fi | |
- name: Send news content via WeChat Bot | |
run: | | |
if [ -n "${{ env.WECHAT_BOT_URL }}" ]; then | |
node -e " | |
const axios = require('axios'); | |
const content = \`${{ env.FORMATTED_CONTENT }}\`; | |
const WECHAT_BOT_URL = '${{ env.WECHAT_BOT_URL }}'; | |
axios.post(WECHAT_BOT_URL, { | |
msgtype: 'markdown', | |
markdown: { | |
content: content | |
} | |
}).then(response => { | |
console.log(response.data.errmsg || '企业微信 BOT 推送成功'); | |
}).catch(error => { | |
console.error('企业微信 BOT 推送失败: ' + error); | |
process.exit(1); | |
}); | |
" | |
fi |