Auto Update News #18
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: 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/$/<br\/>/g') | |
formatted_content="${formatted_content}<br/><img src=\"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: Send news content via Pushplus with retries | |
run: | | |
echo "Sending news content via Pushplus with retries..." | |
CONTENT="${{ env.FORMATTED_CONTENT }}" | |
PUSHPLUS_URL="https://www.pushplus.plus/send" | |
PUSHPLUS_TOKEN="${{ secrets.PUSHPLUS_TOKEN }}" | |
RETRY_COUNT=0 | |
MAX_RETRIES=3 | |
SUCCESS=false | |
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do | |
echo "Attempt $((RETRY_COUNT + 1))..." | |
RESPONSE=$(curl -s -m 10 -o response.json -w "%{http_code}" -X POST "$PUSHPLUS_URL" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"token": "'"$PUSHPLUS_TOKEN"'", | |
"title": "每天60秒读懂世界", | |
"content": "'"$(echo "$CONTENT" | sed 's/"/\\"/g')"'", | |
"template": "html" | |
}') | |
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1) | |
echo "HTTP Status: $HTTP_STATUS" | |
cat response.json | |
if [ "$HTTP_STATUS" -eq 200 ]; then | |
echo "Pushplus request successful." | |
SUCCESS=true | |
break | |
else | |
echo "Pushplus request failed with status $HTTP_STATUS. Retrying..." | |
RETRY_COUNT=$((RETRY_COUNT + 1)) | |
sleep 5 | |
fi | |
done | |
if [ "$SUCCESS" = false ]; then | |
echo "Pushplus request failed after $MAX_RETRIES attempts." | |
exit 1 | |
fi | |
env: | |
PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }} |