This commit is contained in:
parent
39f45b9e58
commit
a90e0b0508
54
.github/workflows/发布wordpress文章.yml
vendored
54
.github/workflows/发布wordpress文章.yml
vendored
@ -17,55 +17,15 @@ jobs:
|
|||||||
TZ: Asia/Shanghai
|
TZ: Asia/Shanghai
|
||||||
run: date
|
run: date
|
||||||
|
|
||||||
# 1. 读取固件版本 DISTRIB_REVISION.txt
|
#- name: 配置 apt 源为清华源并安装依赖
|
||||||
- name: 读取 DISTRIB_REVISION.txt 中的固件版本
|
# run: |
|
||||||
id: read_firmware
|
# sudo sed -i 's@http://.*.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@' /etc/apt/sources.list
|
||||||
run: |
|
# sudo apt-get update -y
|
||||||
if [ -f DISTRIB_REVISION.txt ]; then
|
# sudo apt-get install -y python3 python3-pip
|
||||||
FIRMWARE_VERSION=$(sed -n '2p' DISTRIB_REVISION.txt | xargs)
|
|
||||||
echo "firmware_version=$FIRMWARE_VERSION" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "固件版本文件不存在,设置默认值" >&2
|
|
||||||
echo "firmware_version=Unknown" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 2. 更新 WordPress 文章
|
- name: 📦 更新文章内容到wordpress
|
||||||
- name: 更新 WordPress 文章
|
|
||||||
env:
|
env:
|
||||||
WORDPRESS_URL: ${{ secrets.WORDPRESS_URL }}
|
WORDPRESS_URL: ${{ secrets.WORDPRESS_URL }}
|
||||||
WORDPRESS_USERNAME: ${{ secrets.WORDPRESS_USERNAME }}
|
WORDPRESS_USERNAME: ${{ secrets.WORDPRESS_USERNAME }}
|
||||||
WORDPRESS_PASSWORD: ${{ secrets.WORDPRESS_PASSWORD }}
|
WORDPRESS_PASSWORD: ${{ secrets.WORDPRESS_PASSWORD }}
|
||||||
POST_ID: 829
|
run: python 发布文章.py
|
||||||
POST_STATUS: "draft"
|
|
||||||
firmware_version: ${{ env.firmware_version }}
|
|
||||||
run: |
|
|
||||||
FORMATTED_TIME=$(TZ='Asia/Shanghai' date "+%Y年%m月%d日")
|
|
||||||
|
|
||||||
# 创建 JSON 数据内容,保持 README 内容的原始格式
|
|
||||||
JSON_PAYLOAD=$(jq -n \
|
|
||||||
--arg title "${FORMATTED_TIME}最新每天更新OpenWRT&LEDE x86/64 软路由精品稳定版固件下载含插件" \
|
|
||||||
--arg post_status "$POST_STATUS" \
|
|
||||||
--arg firmware_version "$firmware_version" \
|
|
||||||
--arg formatted_time "$FORMATTED_TIME" \
|
|
||||||
--rawfile description README.md \
|
|
||||||
'{
|
|
||||||
title: $title,
|
|
||||||
description: $description,
|
|
||||||
post_status: $post_status,
|
|
||||||
custom_fields: [
|
|
||||||
{key: "wb_dl_firmware_version", value: $firmware_version},
|
|
||||||
{key: "wb_dl_kernel_version", value: "6.X"},
|
|
||||||
{key: "wb_dl_file_size", value: "1024MB"},
|
|
||||||
{key: "wb_dl_update_time", value: $formatted_time}
|
|
||||||
]
|
|
||||||
}'
|
|
||||||
)
|
|
||||||
|
|
||||||
# 更新 WordPress 文章
|
|
||||||
RESPONSE=$(curl -s -X POST "$WORDPRESS_URL" \
|
|
||||||
--header "Content-Type: application/json" \
|
|
||||||
--user "$WORDPRESS_USERNAME:$WORDPRESS_PASSWORD" \
|
|
||||||
--data "$JSON_PAYLOAD")
|
|
||||||
|
|
||||||
# 检查响应状态
|
|
||||||
echo "$RESPONSE" | jq . || echo "更新失败"
|
|
4
发布文章.py
4
发布文章.py
@ -10,7 +10,7 @@ wp_username = os.environ['WORDPRESS_USERNAME']
|
|||||||
wp_password = os.environ['WORDPRESS_PASSWORD']
|
wp_password = os.environ['WORDPRESS_PASSWORD']
|
||||||
|
|
||||||
# 设置要更新的文章的ID
|
# 设置要更新的文章的ID
|
||||||
post_id = 785 # 替换为实际的文章ID
|
post_id = 829 # 替换为实际的文章ID
|
||||||
|
|
||||||
# 创建一个客户端实例
|
# 创建一个客户端实例
|
||||||
client = xmlrpc.client.ServerProxy(wp_url)
|
client = xmlrpc.client.ServerProxy(wp_url)
|
||||||
@ -19,7 +19,7 @@ client = xmlrpc.client.ServerProxy(wp_url)
|
|||||||
post = client.metaWeblog.getPost(post_id, wp_username, wp_password)
|
post = client.metaWeblog.getPost(post_id, wp_username, wp_password)
|
||||||
|
|
||||||
# 从文件中读取新的文章内容
|
# 从文件中读取新的文章内容
|
||||||
with open('WP.txt', 'r', encoding='utf-8') as file:
|
with open('README.md', 'r', encoding='utf-8') as file:
|
||||||
new_content = file.read()
|
new_content = file.read()
|
||||||
|
|
||||||
# 从 DISTRIB_REVISION.txt 文件中读取固件版本
|
# 从 DISTRIB_REVISION.txt 文件中读取固件版本
|
||||||
|
Loading…
Reference in New Issue
Block a user