项目版本目录重命名为case_1 + 新增短视频账号分析技能(含旧梦留声机_50880435438快速诊断)
This commit is contained in:
1 parent
664efa39b6
commit
2eec65a90f
343 files changed
+2382
-664
No files matched your search
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
简易包装脚本:先保存 RedFox API 原始 JSON,再运行诊断输出。
|
||||
用法: python fetch_and_diagnose.py <抖音号> <账号名称> <输出目录>
|
||||
API Key: 从环境变量 REDFOX_API_KEY 读取
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
|
||||
API_URL = "https://redfox.hk/story/api/dyUser/queryData"
|
||||
SOURCE = "抖音账号诊断-GitHub"
|
||||
|
||||
def _is_chinese(s):
|
||||
return any("\u4e00" <= ch <= "\u9fff" for ch in s)
|
||||
|
||||
def fetch_raw(keyword, api_key):
|
||||
"""调用红狐API,返回完整响应JSON。"""
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"X-API-KEY": api_key,
|
||||
}
|
||||
if _is_chinese(keyword):
|
||||
payload_key = "accountNames"
|
||||
else:
|
||||
payload_key = "accountIds"
|
||||
payload = json.dumps({payload_key: [keyword], "source": SOURCE}).encode("utf-8")
|
||||
req = urllib.request.Request(API_URL, data=payload, headers=headers, method="POST")
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 4:
|
||||
print("用法: python fetch_and_diagnose.py <抖音号> <账号名称> <输出目录>")
|
||||
sys.exit(1)
|
||||
|
||||
keyword = sys.argv[1]
|
||||
account_name = sys.argv[2]
|
||||
output_dir = sys.argv[3]
|
||||
api_key = os.environ.get("REDFOX_API_KEY")
|
||||
if not api_key:
|
||||
print("[错误] 未设置 REDFOX_API_KEY 环境变量")
|
||||
sys.exit(1)
|
||||
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
today = datetime.now().strftime("%Y%m%d")
|
||||
|
||||
# 1. 获取并保存原始 JSON
|
||||
print(f"正在获取原始数据: {keyword} ...")
|
||||
raw = fetch_raw(keyword, api_key)
|
||||
raw_path = os.path.join(output_dir, f"00_原始数据_{today}.json")
|
||||
with open(raw_path, "w", encoding="utf-8") as f:
|
||||
json.dump(raw, f, ensure_ascii=False, indent=2)
|
||||
print(f"原始数据已保存: {raw_path}")
|
||||
|
||||
# 2. 提取账号数据并调用诊断
|
||||
if raw.get("code") != 2000 or not raw.get("data"):
|
||||
print(f"[错误] API返回异常: code={raw.get('code')}, msg={raw.get('msg', '')}")
|
||||
sys.exit(1)
|
||||
|
||||
acc = raw["data"][0]
|
||||
|
||||
# 3. 运行诊断(直接复用 douyin_diagnosis 的诊断逻辑)
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from importlib import import_module
|
||||
diag_script = "D:/github/技能百宝箱/ThirdPartySkills/.workbuddy/skills/douyin-account-diagnosis/scripts/douyin_diagnosis.py"
|
||||
|
||||
# 用 exec 加载以确保工作
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location("douyin_diagnosis", diag_script)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
|
||||
report = mod.generate_report(acc)
|
||||
print(report)
|
||||
|
||||
# 4. 保存纯文本诊断报告
|
||||
txt_path = os.path.join(output_dir, f"00_快速诊断报告_{today}.md")
|
||||
with open(txt_path, "w", encoding="utf-8") as f:
|
||||
f.write(report)
|
||||
print(f"诊断报告已保存: {txt_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user