按站点指定下载日期偏移(0=今天…30)+ 修复启动陈旧登录态
偏移量功能(前端/API 可配,服务端持久化、多用户共享): - state_store:新增 site_config 表 + get_offset / set_offset(0..30 钳制) / get_all_offsets - server:新增 GET/PUT /config(百世锁定当天,不可配置) - 顺心/中通/韵达/安能(各 expected+actual):日期逻辑由 query_days 范围改为读 offset 算单日 target=今天-offset,起止同日;百世仍走当日 - config.example.yaml:query_days 标记为已废弃 修复启动时显示上一会话陈旧登录态: - state_store:新增 reset_login_states(登录态会话级,启动重置为 unknown;数据态会话无关、保留) - runtime.launch_and_prepare:启动时对各站重置登录态,心跳就绪后重新探测写真实值 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from datetime import datetime, timedelta
|
||||
import pandas as pd
|
||||
|
||||
from paths import DOWNLOAD_DIR, CONFIG_PATH
|
||||
import state_store
|
||||
|
||||
|
||||
def with_retry(site_name, label, flow, reset, max_attempts=3):
|
||||
@@ -214,23 +215,14 @@ def shunxin_expected_download_impl(page, out_tag=""):
|
||||
page.get_by_role("button", name="强卸").wait_for(state="visible")
|
||||
print("✅ 车辆点到界面加载完毕")
|
||||
|
||||
# 2. 从配置读取时间偏移量并动态设置日期选择器
|
||||
query_days = 1
|
||||
try:
|
||||
if os.path.exists(CONFIG_PATH):
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f) or {}
|
||||
query_days = int(config.get("shunxin", {}).get("query_days", 1))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. 读取服务端日期偏移(0=今天,1=昨天…),单日范围:起止同日
|
||||
offset = state_store.get_offset("顺心")
|
||||
today = datetime.now()
|
||||
start_date = today - timedelta(days=(query_days - 1))
|
||||
|
||||
today_str = today.strftime("%Y-%m-%d")
|
||||
start_date_str = start_date.strftime("%Y-%m-%d")
|
||||
|
||||
print(f">> 正在设置查询时间范围: [{start_date_str}] 至 [{today_str}]...")
|
||||
target = today - timedelta(days=offset)
|
||||
target_str = target.strftime("%Y-%m-%d")
|
||||
start_date_str = target_str
|
||||
today_str = target_str
|
||||
print(f">> 正在设置查询日期: [{target_str}](偏移 {offset},0=今天)...")
|
||||
|
||||
# 分两步精准呼出和点击时间控件
|
||||
print(" >> 设置起始时间...")
|
||||
@@ -541,23 +533,14 @@ def shunxin_actual_download_impl(page, out_tag=""):
|
||||
page.get_by_role("radio", name="1天").wait_for(state="visible")
|
||||
print("✅ 卸车扫描记录界面加载完毕")
|
||||
|
||||
# 2. 从配置读取时间并设置日期选择器
|
||||
query_days = 1
|
||||
try:
|
||||
if os.path.exists(CONFIG_PATH):
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f) or {}
|
||||
query_days = int(config.get("shunxin", {}).get("query_days", 1))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. 读取服务端日期偏移(0=今天,1=昨天…),单日范围:起止同日
|
||||
offset = state_store.get_offset("顺心")
|
||||
today = datetime.now()
|
||||
start_date = today - timedelta(days=(query_days - 1))
|
||||
|
||||
today_str = today.strftime("%Y-%m-%d")
|
||||
start_date_str = start_date.strftime("%Y-%m-%d")
|
||||
|
||||
print(f">> 正在设置查询时间范围: [{start_date_str}] 至 [{today_str}]...")
|
||||
target = today - timedelta(days=offset)
|
||||
target_str = target.strftime("%Y-%m-%d")
|
||||
start_date_str = target_str
|
||||
today_str = target_str
|
||||
print(f">> 正在设置查询日期: [{target_str}](偏移 {offset},0=今天)...")
|
||||
|
||||
# 分两步精准呼出和点击时间控件
|
||||
print(" >> 设置起始时间...")
|
||||
|
||||
Reference in New Issue
Block a user