From 4059494132a1827d1ad384a3372943f7525e312b Mon Sep 17 00:00:00 2001 From: zjf Date: Wed, 28 May 2025 18:23:24 +0800 Subject: [PATCH] rpa m --- src/cluster/rpa.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/cluster/rpa.py b/src/cluster/rpa.py index 17ac884..5bd06ce 100644 --- a/src/cluster/rpa.py +++ b/src/cluster/rpa.py @@ -24,6 +24,7 @@ rpa_image = (modal.Image.debian_slim(python_version="3.11") "mkdir /root/browsers", "playwright install-deps", "playwright install chromium", + "playwright install msedge", ]) .add_local_python_source('cluster') .add_local_python_source('BowongModalFunctions') @@ -456,6 +457,10 @@ with rpa_image.imports(): webcast_id: str = data.live_id logger.info(f"Starting RPA run for webcast_id: {webcast_id}") + + live_url = f"https://bowong-gateway.bowong.cc/api/t1/live/liveUrl?name={data.live_stream_name}" + result = LiveStreamResult(live_id=webcast_id, live_stream_url=live_url) + # createLivePull2Push with httpx.Client() as client: res = client.post(url="https://bowong-gateway.bowong.cc/api/t1/live/createLivePull2Push", json={ @@ -469,17 +474,18 @@ with rpa_image.imports(): data_res = res.json() print(f"!!!!!! data_res:{data_res}") if status_code == 200 and data_res['code'] == 0: - live_url = f"https://bowong-gateway.bowong.cc/api/t1/live/liveUrl?name={data.live_stream_name}" - result = LiveStreamResult(live_id=webcast_id, live_stream_url=live_url) result.ext_data = data_res['data'] + else: + result.msg="createLivePull2Push 推流失败" + return data_res async with async_playwright() as p: - browser: Browser = await p.chromium.launch(headless=True) - try: - result = await goto_live(browser, data, result, webcast_id) - except BaseException as e: - logger.error(f"Failed to start RPA run: {str(e)}") - await browser.close() + browser: Browser = await p.chromium.launch(headless=True, channel='msedge') + # browser = await p.chromium.launch(channel="msedge") + + + result = await goto_live(browser, data, result, webcast_id) + # Save result to JSON file with ULID naming,TODO 后续s3上传 await save_result_to_json(result, data) @@ -487,7 +493,7 @@ with rpa_image.imports(): return result.dict() # Return as dict for JSON compatibility - @retry(stop=stop_after_attempt(3), wait=wait_fixed(5)) + # @retry(stop=stop_after_attempt(3), wait=wait_fixed(5)) async def goto_live(browser, data: LiveStreamProductWatchRequest, result: LiveStreamResult, webcast_id): context = await browser.new_context() await context.add_cookies(cookies) @@ -495,10 +501,13 @@ with rpa_image.imports(): page: Page = await context.new_page() url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1" logger.info(f"Navigating to {url}") - await page.goto(url, timeout=60000) - await page.wait_for_load_state("networkidle", timeout=60000) + await page.goto(url,wait_until="domcontentloaded", timeout=1800 * 1000) + logger.info(f"Navigating to end {url}") + await page.wait_for_load_state("networkidle", timeout=1800 * 1000) + logger.info(f"Navigating to end {url}") result.title = await page.title() - logger.info(f"Retrieved title: {result.title}") + logger.info(f"------Retrieved title: {result.title}") + live_status = await get_live_status_by_web_page(page, webcast_id) if live_status == LIVE_END: @@ -521,7 +530,7 @@ with rpa_image.imports(): # 312898731614 # webcast_ids = ["36861064178"] # webcast_ids = ["36861064178"] - webcast_id = "206240580433" + webcast_id = "629972366172" data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id) # TODO other info