按站点指定下载日期偏移(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:
Misaka
2026-07-17 21:27:52 +08:00
parent 66bd8af421
commit 26a94999dc
8 changed files with 151 additions and 106 deletions

View File

@@ -40,6 +40,7 @@ import yaml
sys.stdout.reconfigure(encoding="utf-8")
from paths import DOWNLOAD_DIR, CONFIG_PATH
import state_store
def with_retry(site_name, label, flow, reset, max_attempts=3):
@@ -866,12 +867,13 @@ def anneng_expected_download_impl():
# 清理上次的最终文件,避免本次无数据/失败时残留旧数据误导比对
_remove_if_exists(os.path.join(download_dir, FINAL_FILENAME))
query_days = _load_query_days()
offset = state_store.get_offset("安能")
today = datetime.now()
start = today - timedelta(days=(query_days - 1))
start_str = f"{start.year}-{start.month:02d}-{start.day:02d}"
today_str = f"{today.year}-{today.month:02d}-{today.day:02d}"
print(f">> 查询时间范围: [{start_str}] 至 [{today_str}](近 {query_days} 天)")
target = today - timedelta(days=offset)
target_str = f"{target.year}-{target.month:02d}-{target.day:02d}"
start_str = target_str
today_str = target_str
print(f">> 查询日期: [{target_str}](偏移 {offset}0=今天)")
main_cdp = find_main_page_cdp()
export_times = []
@@ -1171,12 +1173,12 @@ def anneng_actual_download_impl():
# 清理上次的最终文件,避免本次无数据/失败时残留旧数据误导比对
_remove_if_exists(os.path.join(download_dir, ACTUAL_FINAL_FILENAME))
days = _load_query_days()
offset = state_store.get_offset("安能")
today = datetime.now()
start = today - timedelta(days=days - 1)
start_str = f"{start.year}/{start.month:02d}/{start.day:02d} 00:00:00"
end_str = f"{today.year}/{today.month:02d}/{today.day:02d} 23:59:59"
print(f">> 扫描时间范围: [{start_str}][{end_str}] {days} 天)")
target = today - timedelta(days=offset)
start_str = f"{target.year}/{target.month:02d}/{target.day:02d} 00:00:00"
end_str = f"{target.year}/{target.month:02d}/{target.day:02d} 23:59:59"
print(f">> 扫描日期: [{start_str}{end_str}]偏移 {offset}0=今天)")
main_cdp = find_main_page_cdp()
try: