每日账单脚本:胜算该区间无数据时按跳过处理(不算失败)

This commit is contained in:
qiuxiang 2026-10-06 17:46:31 +08:00
parent 73af15f2db
commit f774e75fce
2 changed files with 18 additions and 1 deletions

View File

@ -192,7 +192,20 @@ for (let attempt = 1; attempt <= 4 && !countText; attempt++) {
log(`查询第${attempt}次:笔数=${countText},新请求=${seen.list.length - before}`);
if (!countText) await sleep(2000);
}
if (!countText) throw new Error('查询未返回数据');
if (!countText) {
// 胜算该区间还没有账单(如当月账单尚未拉取)时按“无数据”结束,不算失败。
const noData = await evaluate(cdp, sid, `((document.body.innerText || '').includes('暂无数据'))`);
if (noData) {
log('该区间胜算暂无数据,跳过导出:' + monthStart + ' ~ ' + through);
fs.writeFileSync(path.join(OUT_DIR, 'last-export.json'), JSON.stringify({
platform: platformKey, platformLabel: platform.label, empty: true,
monthStart, through, pageCount: 0,
}, null, 2));
close();
process.exit(0);
}
throw new Error('查询未返回数据');
}
log('页面笔数:', countText);
// 3) 导出——同样带重试

View File

@ -79,6 +79,10 @@ try {
if ($LASTEXITCODE -ne 0) { Write-Log ($spec.label + ' 导出失败(exit=' + $LASTEXITCODE + ')'); continue }
$summary = Get-Content -LiteralPath (Join-Path $exportDir 'last-export.json') -Raw | ConvertFrom-Json
if ($summary.empty) {
Write-Log ($spec.label + ':该区间胜算暂无数据,跳过(未改动生产)')
continue
}
$rawFile = $summary.file
$csvFile = [IO.Path]::ChangeExtension($rawFile, '.csv')
$conv = (& $python (Join-Path $root 'xlsx-to-csv.py') $rawFile $csvFile 2>&1 | Out-String)