rpa m
This commit is contained in:
parent
4001249d53
commit
a785e4fc63
|
|
@ -1,5 +1,5 @@
|
||||||
MODAL_ENVIRONMENT=dev
|
MODAL_ENVIRONMENT=dev
|
||||||
modal_app_name=bowong-ai-video
|
modal_app_name=rpa
|
||||||
S3_mount_dir=/mntS3
|
S3_mount_dir=/mntS3
|
||||||
S3_bucket_name=modal-media-cache
|
S3_bucket_name=modal-media-cache
|
||||||
S3_region=ap-northeast-2
|
S3_region=ap-northeast-2
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import os
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
import httpx
|
import httpx
|
||||||
from ulid import ULID
|
from ulid import ULID
|
||||||
|
|
||||||
|
|
@ -442,8 +444,36 @@ def submit_job(data: LiveStreamProductWatchRequest):
|
||||||
return call.object_id
|
return call.object_id
|
||||||
|
|
||||||
|
|
||||||
|
def submit_job_new(data: LiveStreamProductWatchRequest):
|
||||||
|
call = rpa_new.spawn(data)
|
||||||
|
return call.object_id
|
||||||
|
|
||||||
|
|
||||||
########################################rpa_image start######################################################
|
########################################rpa_image start######################################################
|
||||||
with rpa_image.imports():
|
with (rpa_image.imports()):
|
||||||
|
@app.function(timeout=8 * 60 * 60, volumes={"/data": rpa_vol}, cloud="gcp", region="ap")
|
||||||
|
async def rpa_new(data: LiveStreamProductWatchRequest):
|
||||||
|
webcast_id = data.live_id
|
||||||
|
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
||||||
|
print(url)
|
||||||
|
async with async_playwright() as p:
|
||||||
|
browser: Browser = await p.chromium.launch(headless=True, channel='msedge')
|
||||||
|
context = await browser.new_context()
|
||||||
|
await context.add_cookies(cookies)
|
||||||
|
print("Loaded cookies")
|
||||||
|
|
||||||
|
page = await context.new_page()
|
||||||
|
await page.goto(url)
|
||||||
|
|
||||||
|
print("goto end")
|
||||||
|
|
||||||
|
print("title:", await page.title())
|
||||||
|
|
||||||
|
await page.wait_for_load_state("networkidle")
|
||||||
|
|
||||||
|
await browser.close()
|
||||||
|
|
||||||
|
|
||||||
@app.function(timeout=8 * 60 * 60, volumes={"/data": rpa_vol}, cloud="gcp", region="ap")
|
@app.function(timeout=8 * 60 * 60, volumes={"/data": rpa_vol}, cloud="gcp", region="ap")
|
||||||
async def rpa_run(data: LiveStreamProductWatchRequest) -> dict:
|
async def rpa_run(data: LiveStreamProductWatchRequest) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|
@ -470,12 +500,17 @@ with rpa_image.imports():
|
||||||
"liveId": data.live_id
|
"liveId": data.live_id
|
||||||
}, headers={
|
}, headers={
|
||||||
"Authentication": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWQiOiI5ZjIwZDM0MC0xY2U0LTQ5MzAtYTA5NC0yZjM2ODYzNGRiYzciLCJ1aWQiOiI1ZTQzYTc1ZC1hN2M3LTQ1NjQtOTI0OS01NWEyMDIxZDk0YzUiLCJ1c24iOiJ1c2VyQGJvd29uZ2FpLmNvbSIsImV4cCI6MTc0ODQxNjA1Nn0.IWMxl47oSFJyNYQV6M511-rU8GDIGh8r9H5Yt8LShGw"})
|
"Authentication": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWQiOiI5ZjIwZDM0MC0xY2U0LTQ5MzAtYTA5NC0yZjM2ODYzNGRiYzciLCJ1aWQiOiI1ZTQzYTc1ZC1hN2M3LTQ1NjQtOTI0OS01NWEyMDIxZDk0YzUiLCJ1c24iOiJ1c2VyQGJvd29uZ2FpLmNvbSIsImV4cCI6MTc0ODQxNjA1Nn0.IWMxl47oSFJyNYQV6M511-rU8GDIGh8r9H5Yt8LShGw"})
|
||||||
status_code = res.raise_for_status().status_code
|
try:
|
||||||
print(status_code)
|
res.raise_for_status()
|
||||||
|
except BaseException as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
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 data_res is not None \
|
||||||
|
and 'code' in data_res \
|
||||||
|
and data_res['code'] == 0:
|
||||||
|
|
||||||
result.ext_data = data_res['data']
|
result.ext_data = data_res['data']
|
||||||
else:
|
else:
|
||||||
result.msg = "createLivePull2Push 推流失败"
|
result.msg = "createLivePull2Push 推流失败"
|
||||||
|
|
@ -500,7 +535,7 @@ with rpa_image.imports():
|
||||||
await context.add_cookies(cookies)
|
await context.add_cookies(cookies)
|
||||||
logger.info("Loaded cookies")
|
logger.info("Loaded cookies")
|
||||||
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&from_search=true"
|
||||||
logger.info(f"Navigating to {url}")
|
logger.info(f"Navigating to {url}")
|
||||||
await page.goto(url, wait_until="domcontentloaded")
|
await page.goto(url, wait_until="domcontentloaded")
|
||||||
logger.info(f"Navigating to end {url}")
|
logger.info(f"Navigating to end {url}")
|
||||||
|
|
@ -539,11 +574,13 @@ with rpa_image.imports():
|
||||||
# 312898731614
|
# 312898731614
|
||||||
# webcast_ids = ["36861064178"]
|
# webcast_ids = ["36861064178"]
|
||||||
# webcast_ids = ["36861064178"]
|
# webcast_ids = ["36861064178"]
|
||||||
webcast_id = "333555252930"
|
webcast_id = "65731953339"
|
||||||
|
|
||||||
data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id,live_stream_name=str(ULID()))
|
data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id,
|
||||||
|
live_stream_name=str(ULID()))
|
||||||
# TODO other info
|
# TODO other info
|
||||||
call_id = submit_job(data)
|
call_id = submit_job(data)
|
||||||
|
# call_id = submit_job_new(data)
|
||||||
print("------call_id:", call_id)
|
print("------call_id:", call_id)
|
||||||
result = get_job_result(call_id, 8 * 60 * 60)
|
result = get_job_result(call_id, 8 * 60 * 60)
|
||||||
# result = get_job_result(call_id)
|
# result = get_job_result(call_id)
|
||||||
|
|
@ -563,8 +600,8 @@ with rpa_image.imports():
|
||||||
# title = await rpa_run.remote.aio(webcast_id="36861064178")
|
# title = await rpa_run.remote.aio(webcast_id="36861064178")
|
||||||
# logger.info(f"title = {title}")
|
# logger.info(f"title = {title}")
|
||||||
|
|
||||||
########################################rpa_image end######################################################
|
|
||||||
|
|
||||||
|
########################################rpa_image end######################################################
|
||||||
|
|
||||||
|
|
||||||
def local_main_test():
|
def local_main_test():
|
||||||
|
|
@ -579,6 +616,7 @@ def local_main_test():
|
||||||
print(status_code)
|
print(status_code)
|
||||||
print(res.json())
|
print(res.json())
|
||||||
|
|
||||||
|
|
||||||
def foo(webcast_id):
|
def foo(webcast_id):
|
||||||
with sync_playwright() as p:
|
with sync_playwright() as p:
|
||||||
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
||||||
|
|
@ -591,8 +629,4 @@ def foo(webcast_id):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# local_main_test()
|
|
||||||
foo("333555252930")
|
|
||||||
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue