feat(xq0041): 经营宝登录改人工点确认 + 双公司独立档案与执行模式拆分(1.3.9)
- 登录改为自动填账号密码并勾选用户协议,页面右上角浮层提示人工点「登录」(按钮、滑块/短信、选门店仍人工),登录一次长期复用 - 金色印象 / 金色湖畔各自独立浏览器档案与调试端口(xq0041 / xq0041_b,9222 / 9333),避免同浏览器反复切号触发风控 - 执行模式拆 full(只导金色印象 + 并台账 + 更新核对统计)/ export_only(按范围勾选各导一份,不写表),湖畔报表文件名带「金色湖畔_」前缀;UI 同步重建
This commit is contained in:
@@ -100,7 +100,7 @@ def download(page, d_from, d_to, save_dir, dry_run=False):
|
||||
if match_key in (it.get('timeInterval') or '') and it.get('downloadLink')]
|
||||
fresh = [it for it in cands if _age_minutes(it.get('addTime')) <= config.REUSE_MAX_AGE_MIN]
|
||||
if fresh and not dry_run:
|
||||
target = fresh[0]
|
||||
target = max(fresh, key=lambda x: str(x.get('addTime') or ''))
|
||||
config.log(f'复用 {_age_minutes(target.get("addTime")):.0f} 分钟前的同区间记录'
|
||||
f'(阈值 {config.REUSE_MAX_AGE_MIN} 分钟),不重复生成')
|
||||
elif cands:
|
||||
@@ -127,32 +127,44 @@ def download(page, d_from, d_to, save_dir, dry_run=False):
|
||||
continue
|
||||
return {'ok': False, 'message': f'生成任务提交失败:{msg}'}
|
||||
|
||||
# 平台是「先登记一条记录(此时 downloadLink 为空)→ 文件生成完再回填链接」,
|
||||
# 所以必须等 downloadLink 出现才算就绪,否则一命中空记录就退出等待(3 秒即失败)。
|
||||
deadline = time.time() + config.RECORD_SECONDS
|
||||
waited = 0
|
||||
last_log = -config.POLL_LOG_EVERY
|
||||
while time.time() < deadline:
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
waited += config.POLL_SECONDS
|
||||
items = _history_items(frame)
|
||||
for it in items:
|
||||
if it.get('id') in before_ids:
|
||||
continue
|
||||
if match_key not in (it.get('timeInterval') or ''):
|
||||
continue
|
||||
target = it
|
||||
hits = [it for it in items
|
||||
if it.get('id') not in before_ids
|
||||
and match_key in (it.get('timeInterval') or '')]
|
||||
ready = [it for it in hits if it.get('downloadLink')]
|
||||
if ready:
|
||||
# 同区间可能登记多条(重试/多业务),取最新一条
|
||||
target = max(ready, key=lambda x: str(x.get('addTime') or ''))
|
||||
break
|
||||
if target:
|
||||
break
|
||||
config.log(' 等待账单生成…')
|
||||
if waited - last_log >= config.POLL_LOG_EVERY:
|
||||
last_log = waited
|
||||
if hits:
|
||||
config.log(f' 账单生成中({len(hits)} 条记录暂无 downloadLink,'
|
||||
f'已等 {waited}s / 上限 {config.RECORD_SECONDS}s)…')
|
||||
else:
|
||||
config.log(f' 等待账单生成…(已等 {waited}s)')
|
||||
|
||||
if dry_run:
|
||||
return {'ok': True, 'message': f'[演练] 将生成并下载打款记录 {d_from}~{d_to}', 'rows': total}
|
||||
|
||||
if not target:
|
||||
return {'ok': False, 'message': f'{config.RECORD_SECONDS}s 内未拿到可下载记录'}
|
||||
return {'ok': False,
|
||||
'message': f'{config.RECORD_SECONDS}s 内记录仍未生成完成(无 downloadLink)'}
|
||||
|
||||
link = target.get('downloadLink')
|
||||
if not link:
|
||||
return {'ok': False, 'message': '记录里没有 downloadLink(可能仍在生成)'}
|
||||
|
||||
path = os.path.join(save_dir, f'{config.PAYMENT_NAME_KEY}_{tag}.xlsx')
|
||||
# 公司前缀:金色湖畔落到「金色湖畔_打款记录_20261105.xlsx」,不与金色印象同日文件互相覆盖
|
||||
path = os.path.join(save_dir, f'{config.file_prefix()}{config.PAYMENT_NAME_KEY}_{tag}.xlsx')
|
||||
config.log(f'下载 → {path}')
|
||||
size = browser.download_file(link, path)
|
||||
if not size:
|
||||
|
||||
Reference in New Issue
Block a user