'commit'
This commit is contained in:
@@ -166,6 +166,43 @@ async def get_station_list(d, service, max_stations_count=MAX_STATIONS_COUNT):
|
||||
total_encountered_count -= 1
|
||||
continue
|
||||
|
||||
busy_list = st.get("busy_list") or []
|
||||
piles = []
|
||||
if isinstance(busy_list, list):
|
||||
for bi in busy_list:
|
||||
if not isinstance(bi, dict):
|
||||
continue
|
||||
mode = bi.get("mode") or bi.get("type") or "未知"
|
||||
idle = bi.get("idle")
|
||||
total = bi.get("total")
|
||||
try:
|
||||
idle_val = int(idle) if idle is not None else 0
|
||||
except Exception:
|
||||
idle_val = 0
|
||||
try:
|
||||
total_val = int(total) if total is not None else 0
|
||||
except Exception:
|
||||
total_val = 0
|
||||
piles.append(
|
||||
{
|
||||
"type": mode,
|
||||
"total": total_val,
|
||||
"free": idle_val,
|
||||
}
|
||||
)
|
||||
|
||||
if piles:
|
||||
try:
|
||||
await service.record_station_status(
|
||||
{
|
||||
"station_name": station_name,
|
||||
"piles": piles,
|
||||
"distance": st.get("distance_text"),
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"记录列表页状态失败 ({station_name}): {e}")
|
||||
|
||||
current_idx = total_new_processed_count + 1
|
||||
remaining = max_stations_count - current_idx
|
||||
logger.info(f"--- [进度: {current_idx}/{max_stations_count}, 剩余: {remaining}] 发现新场站 '{station_name}',开始处理... ---")
|
||||
|
||||
@@ -120,6 +120,67 @@ class AiTeJiYiChongService:
|
||||
logger.info(f"三级页面价格详情处理完成: {station_name}, 共 {len(schedule_to_save)} 条记录")
|
||||
return schedule_to_save
|
||||
|
||||
async def record_station_status(self, station_info: dict):
|
||||
"""
|
||||
记录场站状态信息(从列表页 OCR+LLM 抓取到的电桩忙闲数据)
|
||||
"""
|
||||
if not station_info or not isinstance(station_info, dict):
|
||||
return
|
||||
|
||||
name = station_info.get("station_name") or station_info.get("name")
|
||||
if not name:
|
||||
return
|
||||
|
||||
station_hash = self.get_hash(name)
|
||||
now = datetime.now()
|
||||
|
||||
async with await self.db.get_session() as session:
|
||||
profile_id = self.generate_id()
|
||||
await self.station_profile_model.save(
|
||||
session=session,
|
||||
id=profile_id,
|
||||
station_hash=station_hash,
|
||||
operator=self.operator,
|
||||
station_name=name,
|
||||
valid_start_time=now
|
||||
)
|
||||
|
||||
status_id = self.generate_id()
|
||||
|
||||
piles_data = station_info.get("piles")
|
||||
total, free = 0, 0
|
||||
standardized_piles = []
|
||||
if isinstance(piles_data, list):
|
||||
for idx, p in enumerate(piles_data):
|
||||
try:
|
||||
t = int(p.get("total", 0))
|
||||
f = int(p.get("free", 0))
|
||||
total += t
|
||||
free += f
|
||||
standardized_piles.append({
|
||||
"pile_no": f"G{idx+1}",
|
||||
"type": p.get("type", "未知"),
|
||||
"power": "",
|
||||
"status_text": f"空闲{f}/总{t}",
|
||||
"remark": "列表页OCR"
|
||||
})
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
await self.station_status_model.save(
|
||||
session=session,
|
||||
id=status_id,
|
||||
station_hash=station_hash,
|
||||
total_piles=total,
|
||||
free_piles=free,
|
||||
piles_detail_json=standardized_piles if standardized_piles else None,
|
||||
current_price=self._to_float(station_info.get("price")),
|
||||
parking_info=station_info.get("parking"),
|
||||
distance=station_info.get("distance") or station_info.get("distance_text"),
|
||||
valid_start_time=now
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
async def process_station_detail(self, image_path, station_name=None) -> dict:
|
||||
"""
|
||||
处理场站详情页截图
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -302,8 +302,11 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
"""
|
||||
在详情页提取价格和状态信息
|
||||
"""
|
||||
first_screen_path = take_screenshot(d, f"tld_detail_basic_{get_name_md5(station_name)}_{int(time.time())}.jpg")
|
||||
station_name = station_info.get("name")
|
||||
first_screen_path = take_screenshot(
|
||||
d,
|
||||
f"tld_detail_basic_{get_name_md5(station_name)}_{int(time.time())}.jpg",
|
||||
)
|
||||
address = station_info.get("address")
|
||||
distance = station_info.get("distance")
|
||||
total_piles = None
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user