This commit is contained in:
HuangHai
2026-01-15 21:52:14 +08:00
parent ae9276c6b5
commit 914db4d782
2 changed files with 14 additions and 26 deletions

View File

@@ -2,7 +2,7 @@
# 采集配置 # 采集配置
SCROLL_DISTANCE_RATIO = 0.3 SCROLL_DISTANCE_RATIO = 0.3
MAX_STATIONS_COUNT = 30 MAX_STATIONS_COUNT = 20
FIRST_RUN_ONLY_ONE_STATION = False FIRST_RUN_ONLY_ONE_STATION = False
REDIS_STATION_EXPIRE = 120 REDIS_STATION_EXPIRE = 120

View File

@@ -1,13 +1,13 @@
import asyncio import asyncio
import json import json
import logging import logging
import os import os
import re import re
import sys import sys
import zipfile import zipfile
from datetime import datetime from datetime import datetime
from decimal import Decimal from decimal import Decimal
from typing import Any, Dict, List, Optional, Set from typing import Any, Dict, List, Optional, Set
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -516,7 +516,7 @@ async def main():
limit = None limit = None
operators = ["新电途", "特来电", "驿来特", "艾特吉易充"] operators = ["新电途", "特来电", "驿来特", "艾特吉易充"]
excel_paths: List[str] = [] excel_paths: List[str] = []
ts = datetime.now().strftime("%Y%m%d_%H%M%S") ts = datetime.now().strftime("%Y%m%d_%H%M%S")
export_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Excel", ts) export_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Excel", ts)
@@ -530,28 +530,16 @@ async def main():
output_filename = f"{operator}_{ts}.xlsx" output_filename = f"{operator}_{ts}.xlsx"
output_path = os.path.join(export_dir, output_filename) output_path = os.path.join(export_dir, output_filename)
logger.info(f"--- 正在导出 {operator} ---") logger.info(f"--- 正在导出 {operator} ---")
if limit is not None: if limit is not None:
logger.info(f"限制导出记录数: {limit}") logger.info(f"限制导出记录数: {limit}")
try: try:
final_path = await export_excel(operator, output_path, limit=limit) final_path = await export_excel(operator, output_path, limit=limit)
logger.info(f"{operator} 导出完成: {final_path}") logger.info(f"{operator} 导出完成: {final_path}")
excel_paths.append(final_path) excel_paths.append(final_path)
except Exception as e: except Exception as e:
logger.error(f"{operator} 导出失败: {e}") logger.error(f"{operator} 导出失败: {e}")
if excel_paths:
zip_filename = f"充电场站数据_{ts}.zip"
zip_path = os.path.join(export_dir, zip_filename)
try:
with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
for path in excel_paths:
if os.path.isfile(path):
zf.write(path, arcname=os.path.basename(path))
logger.info(f"ZIP 打包完成: {zip_path}")
except Exception as e:
logger.error(f"ZIP 打包失败: {e}")
logger.info("所有导出任务已结束。") logger.info("所有导出任务已结束。")