'commit'
This commit is contained in:
@@ -286,6 +286,7 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
free_piles = None
|
||||
piles_detail = None
|
||||
parking_info = None
|
||||
submitted_price_task = False
|
||||
|
||||
logger.info(f"[详情页] 进入 crawl_detail_logic,场站: {station_name} | 地址: {address}")
|
||||
logger.info(f"[详情页] 已截取首屏截图,准备识别基础信息: {first_screen_path}")
|
||||
@@ -303,6 +304,15 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
free_piles = basic_info.get("free_piles")
|
||||
piles_detail = basic_info.get("piles_detail")
|
||||
parking_info = basic_info.get("parking_info")
|
||||
|
||||
if total_piles is None and isinstance(station_info, dict):
|
||||
tp = station_info.get("total_piles")
|
||||
if tp is not None:
|
||||
total_piles = tp
|
||||
if free_piles is None and isinstance(station_info, dict):
|
||||
fp = station_info.get("free_piles")
|
||||
if fp is not None:
|
||||
free_piles = fp
|
||||
|
||||
logger.info(f"[详情页] 基础信息识别结果: {station_name} | {address} | 桩数: {total_piles}/{free_piles} | 停车费: {parking_info}")
|
||||
except Exception as ex:
|
||||
@@ -388,8 +398,7 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
fail_screen = take_screenshot(d, f"tld_ocr_fail_{int(time.time())}.jpg")
|
||||
logger.error(f"❌ [OCR失败] 经过 {max_scroll_attempts} 次滚动仍未在页面中找到价格入口文字 (全部时段/全天价格统一)!")
|
||||
logger.error(f"❌ [OCR失败] 最终截图已保存至: {fail_screen}")
|
||||
logger.error("❌ [OCR失败] 程序将停止运行,请检查页面内容或识别逻辑。")
|
||||
sys.exit(1) # 停止程序
|
||||
logger.error("❌ [OCR失败] 将不进入电价页,继续以当前信息写入基础数据。")
|
||||
except Exception as e:
|
||||
logger.error(f"[详情页] 识别或点击价格入口失败: {e}")
|
||||
|
||||
@@ -447,6 +456,8 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
task = asyncio.create_task(
|
||||
self._analyze_and_save_prices_async(
|
||||
station_name=station_name,
|
||||
address=address,
|
||||
distance=distance,
|
||||
price_screenshots=price_screenshots,
|
||||
total_piles=total_piles,
|
||||
free_piles=free_piles,
|
||||
@@ -455,7 +466,25 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
)
|
||||
)
|
||||
self.pending_price_tasks.append(task)
|
||||
submitted_price_task = True
|
||||
logger.info(f"[详情页] 已后台提交 {len(price_screenshots)} 张电价截图进行识别与保存,继续后续流程不阻塞。")
|
||||
else:
|
||||
pass
|
||||
|
||||
if not submitted_price_task:
|
||||
try:
|
||||
await self.service.save_station_profile_and_status(
|
||||
station_name=station_name,
|
||||
address=address,
|
||||
total_piles=total_piles,
|
||||
free_piles=free_piles,
|
||||
piles_detail=piles_detail,
|
||||
parking_info=parking_info,
|
||||
distance=distance
|
||||
)
|
||||
logger.info(f"[详情页] 已基于整合信息写入基础数据: {station_name}")
|
||||
except Exception as e:
|
||||
logger.error(f"[详情页] 写入基础数据失败: {e}")
|
||||
|
||||
async def crawl_list(self):
|
||||
"""
|
||||
@@ -471,7 +500,7 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
# 逻辑已在 crawl_list_logic 中通过 crawl_detail_logic 调用
|
||||
pass
|
||||
|
||||
async def _analyze_and_save_prices_async(self, station_name, price_screenshots, total_piles=None, free_piles=None, piles_detail=None, parking_info=None):
|
||||
async def _analyze_and_save_prices_async(self, station_name, address, distance, price_screenshots, total_piles=None, free_piles=None, piles_detail=None, parking_info=None):
|
||||
all_prices = []
|
||||
sem = asyncio.Semaphore(self.vlm_concurrency)
|
||||
|
||||
@@ -509,15 +538,17 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
|
||||
unique_prices.sort(key=lambda x: x.get("start", "00:00"))
|
||||
|
||||
await self.service.process_price_detail_data(
|
||||
station_name,
|
||||
unique_prices,
|
||||
await self.service.save_station_data(
|
||||
station_name=station_name,
|
||||
address=address,
|
||||
prices=unique_prices,
|
||||
total_piles=total_piles,
|
||||
free_piles=free_piles,
|
||||
piles_detail=piles_detail,
|
||||
parking_info=parking_info
|
||||
parking_info=parking_info,
|
||||
distance=distance,
|
||||
)
|
||||
logger.info(f"[详情页] {station_name} 后台价格信息处理完成,共 {len(unique_prices)} 条时段")
|
||||
logger.info(f"[详情页] {station_name} 后台价格信息处理完成,共 {len(unique_prices)} 条时段,并已写入数据库。")
|
||||
except Exception as e:
|
||||
logger.error(f"[详情页] 后台处理价格截图失败: {e}")
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user