63 lines
2.1 KiB
Bash
Executable File
63 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
||
# ============================================================================
|
||
# 程序名称: novel-sync-status.sh
|
||
# 功能: 同步章节后自动更新发表记录
|
||
# ============================================================================
|
||
|
||
NOVEL_DIR="/root/.openclaw/workspace/平安书"
|
||
RECORD_FILE="$NOVEL_DIR/章节发表记录.md"
|
||
TIMESTAMP=$(date '+%Y-%m-%d %H:%M')
|
||
|
||
echo "╔════════════════════════════════════════════════════╗"
|
||
echo "║ 平安书发表记录自动更新模块 ║"
|
||
echo "╚════════════════════════════════════════════════════╝"
|
||
echo ""
|
||
|
||
# 1. 获取最新章节(不含_完整重写版等后缀)
|
||
latest_chapter=$(ls -t "$NOVEL_DIR"/第*章_*.txt 2>/dev/null | head -1 | xargs -I {} basename {})
|
||
|
||
if [ -z "$latest_chapter" ]; then
|
||
echo "ℹ️ 未发现章节文件"
|
||
exit 0
|
||
fi
|
||
|
||
echo "📖 最新章节: $latest_chapter"
|
||
|
||
# 2. 提取章节号和标题
|
||
chapter_num=$(echo "$latest_chapter" | grep -oE "第[0-9]+章")
|
||
chapter_title=$(echo "$latest_chapter" | sed 's/.*第[0-9]*章[_-]*//' | sed 's/.txt$//')
|
||
|
||
# 3. 计算字数
|
||
word_count=$(python3 -c "
|
||
import sys
|
||
with open('$NOVEL_DIR/$latest_chapter', 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
count = sum(1 for c in content if '\u4e00' <= c <= '\u9fff')
|
||
print(count)
|
||
" 2>/dev/null)
|
||
|
||
[ -z "$word_count" ] && word_count="未知"
|
||
|
||
echo "📊 字数: $word_count"
|
||
|
||
# 4. 检查是否已在记录中
|
||
if grep -q "$latest_chapter" "$RECORD_FILE" 2>/dev/null; then
|
||
echo "ℹ️ 章节已在记录中: $latest_chapter"
|
||
else
|
||
echo "🆕 发现新章节,添加到发表记录..."
|
||
|
||
# 追加到待办列表
|
||
sed -i "s|## 待办事项|## 待办事项\\
|
||
- [x] $latest_chapter ($TIMESTAMP) ✅|" "$RECORD_FILE"
|
||
|
||
echo "✅ 已添加: $latest_chapter"
|
||
fi
|
||
|
||
echo ""
|
||
echo "📋 当前状态:"
|
||
echo " - 最新章节: $latest_chapter"
|
||
echo " - 字数: $word_count"
|
||
echo " - 更新时间: $TIMESTAMP"
|
||
|
||
exit 0
|