Update README
This commit is contained in:
161
deploy_scripts/daily_auto.py
Normal file
161
deploy_scripts/daily_auto.py
Normal file
@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
GFIL 每日推广管线 v3 — 精简版
|
||||
每天 14:00 自动运行 (Windows 计划任务)
|
||||
|
||||
步骤:
|
||||
1. Telegraph SEO 轰炸 (10篇)
|
||||
2. GitHub 建仓库 (5个)
|
||||
3. TG + Discord 推送
|
||||
4. 博客 API 更新
|
||||
5. IndexNow 搜索引擎提交
|
||||
|
||||
用法:
|
||||
python daily_auto.py # 正常执行
|
||||
python daily_auto.py --dry-run # 预览不执行
|
||||
python daily_auto.py --check # 检查配置状态
|
||||
"""
|
||||
import subprocess, sys, os, datetime, argparse
|
||||
|
||||
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT_DIR = os.path.dirname(SCRIPTS_DIR)
|
||||
sys.path.insert(0, ROOT_DIR)
|
||||
from config import BLOG_URL, TOOLS_URL
|
||||
|
||||
# Telegraph → now handled by RackNerd daily_light.py (2/day quality content)
|
||||
STEPS = [
|
||||
{
|
||||
"name": "GitHub 建仓库",
|
||||
"script": "github_blast.py",
|
||||
"desc": "5个仓库,README含TG+Discord+工具外链",
|
||||
"timeout": 120,
|
||||
},
|
||||
{
|
||||
"name": "TG + Discord 推送",
|
||||
"script": "n8n_bridge.py",
|
||||
"desc": "SEO内容推送TG频道+Discord社区",
|
||||
"timeout": 60,
|
||||
},
|
||||
{
|
||||
"name": "博客 API 更新",
|
||||
"script": "blog_api.py",
|
||||
"desc": "更新 /api/tools.json + /api/articles.json",
|
||||
"timeout": 30,
|
||||
},
|
||||
{
|
||||
"name": "IndexNow 搜索引擎提交",
|
||||
"script": "indexnow_submit.py",
|
||||
"desc": "通知Bing/Google/Yandex快速收录新页面",
|
||||
"timeout": 60,
|
||||
},
|
||||
{
|
||||
"name": "Google Indexing API 秒收录",
|
||||
"script": "indexing_api_push.py",
|
||||
"args": "--daily",
|
||||
"desc": "Google Indexing API — 13核心页每日秒收录",
|
||||
"timeout": 120,
|
||||
},
|
||||
]
|
||||
|
||||
def run_step(step, dry_run=False):
|
||||
script = step["script"]
|
||||
script_path = os.path.join(SCRIPTS_DIR, script)
|
||||
|
||||
print(f"\n{'─'*50}")
|
||||
print(f" {step['name']} — {step['desc']}")
|
||||
print(f"{'─'*50}")
|
||||
|
||||
if dry_run:
|
||||
print(f" [DRY-RUN] would run: {script}")
|
||||
return True
|
||||
|
||||
if not os.path.exists(script_path):
|
||||
print(f" SKIP: {script} 不存在")
|
||||
return False
|
||||
|
||||
try:
|
||||
cmd = [sys.executable, script_path]
|
||||
if step.get("args"):
|
||||
cmd.extend(step["args"].split())
|
||||
result = subprocess.run(
|
||||
cmd, capture_output=True, text=True, timeout=step["timeout"],
|
||||
cwd=ROOT_DIR,
|
||||
)
|
||||
# 显示最后几行输出
|
||||
lines = [l for l in result.stdout.strip().split("\n") if l.strip()]
|
||||
for line in lines[-8:]:
|
||||
print(f" {line}")
|
||||
if result.returncode != 0:
|
||||
print(f" WARN: exit code {result.returncode}")
|
||||
if result.stderr.strip():
|
||||
print(f" STDERR: {result.stderr.strip()[:200]}")
|
||||
# Retry once
|
||||
print(f" RETRY: {step['name']} (attempt 2)...")
|
||||
try:
|
||||
r2 = subprocess.run(cmd, capture_output=True, text=True, timeout=step["timeout"], cwd=ROOT_DIR)
|
||||
if r2.returncode == 0:
|
||||
print(f" OK: retry succeeded")
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
return True
|
||||
except subprocess.TimeoutExpired:
|
||||
print(f" ERROR: 超时 ({step['timeout']}s)")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f" ERROR: {e}")
|
||||
return False
|
||||
|
||||
def check():
|
||||
"""检查所有子脚本是否存在"""
|
||||
print("=== 管线健康检查 ===\n")
|
||||
all_ok = True
|
||||
for step in STEPS:
|
||||
script_path = os.path.join(SCRIPTS_DIR, step["script"])
|
||||
exists = os.path.exists(script_path)
|
||||
status = "OK" if exists else "MISSING!"
|
||||
if not exists:
|
||||
all_ok = False
|
||||
print(f" {step['name']}: {step['script']} — {status}")
|
||||
print(f"\n Blog: {BLOG_URL}")
|
||||
print(f" Tools: {TOOLS_URL}")
|
||||
return all_ok
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="GFIL 每日推广管线 v3")
|
||||
parser.add_argument("--dry-run", action="store_true", help="预览模式,不实际执行")
|
||||
parser.add_argument("--check", action="store_true", help="仅检查配置,不执行")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.check:
|
||||
check()
|
||||
return
|
||||
|
||||
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"╔══════════════════════════════════════╗")
|
||||
print(f"║ GFIL Daily Pipeline v3 {ts} ║")
|
||||
if args.dry_run:
|
||||
print(f"║ *** DRY-RUN MODE *** ║")
|
||||
print(f"╚══════════════════════════════════════╝")
|
||||
|
||||
ok = 0
|
||||
fail = 0
|
||||
for step in STEPS:
|
||||
if run_step(step, dry_run=args.dry_run):
|
||||
ok += 1
|
||||
else:
|
||||
fail += 1
|
||||
|
||||
print(f"\n{'='*50}")
|
||||
print(f" Pipeline done: {ok} OK, {fail} FAILED")
|
||||
if ok > 0:
|
||||
print(f" Telegraph → Google indexing in 24-48h")
|
||||
print(f" TG/Discord → 推送已发送")
|
||||
print(f" Blog API → {BLOG_URL}/api/")
|
||||
print(f" IndexNow → 搜索引擎已通知")
|
||||
print(f"{'='*50}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user