rpa m
This commit is contained in:
parent
d97168d0e8
commit
4059494132
|
|
@ -24,6 +24,7 @@ rpa_image = (modal.Image.debian_slim(python_version="3.11")
|
||||||
"mkdir /root/browsers",
|
"mkdir /root/browsers",
|
||||||
"playwright install-deps",
|
"playwright install-deps",
|
||||||
"playwright install chromium",
|
"playwright install chromium",
|
||||||
|
"playwright install msedge",
|
||||||
])
|
])
|
||||||
.add_local_python_source('cluster')
|
.add_local_python_source('cluster')
|
||||||
.add_local_python_source('BowongModalFunctions')
|
.add_local_python_source('BowongModalFunctions')
|
||||||
|
|
@ -456,6 +457,10 @@ with rpa_image.imports():
|
||||||
|
|
||||||
webcast_id: str = data.live_id
|
webcast_id: str = data.live_id
|
||||||
logger.info(f"Starting RPA run for webcast_id: {webcast_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
|
# createLivePull2Push
|
||||||
with httpx.Client() as client:
|
with httpx.Client() as client:
|
||||||
res = client.post(url="https://bowong-gateway.bowong.cc/api/t1/live/createLivePull2Push", json={
|
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()
|
data_res = res.json()
|
||||||
print(f"!!!!!! data_res:{data_res}")
|
print(f"!!!!!! data_res:{data_res}")
|
||||||
if status_code == 200 and data_res['code'] == 0:
|
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']
|
result.ext_data = data_res['data']
|
||||||
|
else:
|
||||||
|
result.msg="createLivePull2Push 推流失败"
|
||||||
|
return data_res
|
||||||
|
|
||||||
async with async_playwright() as p:
|
async with async_playwright() as p:
|
||||||
browser: Browser = await p.chromium.launch(headless=True)
|
browser: Browser = await p.chromium.launch(headless=True, channel='msedge')
|
||||||
try:
|
# browser = await p.chromium.launch(channel="msedge")
|
||||||
result = await goto_live(browser, data, result, webcast_id)
|
|
||||||
except BaseException as e:
|
|
||||||
logger.error(f"Failed to start RPA run: {str(e)}")
|
result = await goto_live(browser, data, result, webcast_id)
|
||||||
await browser.close()
|
|
||||||
|
|
||||||
# Save result to JSON file with ULID naming,TODO 后续s3上传
|
# Save result to JSON file with ULID naming,TODO 后续s3上传
|
||||||
await save_result_to_json(result, data)
|
await save_result_to_json(result, data)
|
||||||
|
|
@ -487,7 +493,7 @@ with rpa_image.imports():
|
||||||
return result.dict() # Return as dict for JSON compatibility
|
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):
|
async def goto_live(browser, data: LiveStreamProductWatchRequest, result: LiveStreamResult, webcast_id):
|
||||||
context = await browser.new_context()
|
context = await browser.new_context()
|
||||||
await context.add_cookies(cookies)
|
await context.add_cookies(cookies)
|
||||||
|
|
@ -495,10 +501,13 @@ with rpa_image.imports():
|
||||||
page: Page = await context.new_page()
|
page: Page = await context.new_page()
|
||||||
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
||||||
logger.info(f"Navigating to {url}")
|
logger.info(f"Navigating to {url}")
|
||||||
await page.goto(url, timeout=60000)
|
await page.goto(url,wait_until="domcontentloaded", timeout=1800 * 1000)
|
||||||
await page.wait_for_load_state("networkidle", timeout=60000)
|
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()
|
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)
|
live_status = await get_live_status_by_web_page(page, webcast_id)
|
||||||
|
|
||||||
if live_status == LIVE_END:
|
if live_status == LIVE_END:
|
||||||
|
|
@ -521,7 +530,7 @@ with rpa_image.imports():
|
||||||
# 312898731614
|
# 312898731614
|
||||||
# webcast_ids = ["36861064178"]
|
# webcast_ids = ["36861064178"]
|
||||||
# webcast_ids = ["36861064178"]
|
# webcast_ids = ["36861064178"]
|
||||||
webcast_id = "206240580433"
|
webcast_id = "629972366172"
|
||||||
|
|
||||||
data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id)
|
data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id)
|
||||||
# TODO other info
|
# TODO other info
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue