Evilmass commited on
Commit ·
72ddf3f
1
Parent(s): ed9b045
fix get_bilibili_live_rooms
Browse files- _playwright/bilibili.py +4 -8
- utils.py +6 -2
_playwright/bilibili.py
CHANGED
|
@@ -70,26 +70,22 @@ async def live(page):
|
|
| 70 |
for room_id in list(bilibili_live_rooms.keys()):
|
| 71 |
await page.goto(f"{bilibili_live_url}/{str(room_id)}")
|
| 72 |
# 输入框选择 xpath 绝对定位
|
| 73 |
-
input_box =
|
| 74 |
"xpath=/html/body/div[3]/main/div[1]/section[1]/div[3]/div[12]/div/div[2]/div[2]/textarea",
|
| 75 |
)
|
| 76 |
# 输入内容
|
| 77 |
await input_box.fill("1")
|
| 78 |
# 发送按钮
|
| 79 |
-
send_button =
|
| 80 |
"xpath=/html/body/div[3]/main/div[1]/section[1]/div[3]/div[12]/div/div[3]/div/button/span"
|
| 81 |
)
|
| 82 |
if await send_button.is_visible():
|
| 83 |
# 点击发送按钮
|
| 84 |
await send_button.click()
|
| 85 |
-
room_msg = (
|
| 86 |
-
f"直播间:【{bilibili_live_rooms[room_id]}】打卡成功,打卡时间:【{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}】"
|
| 87 |
-
)
|
| 88 |
bilibili_logger.info(room_msg)
|
| 89 |
else:
|
| 90 |
-
room_msg = (
|
| 91 |
-
f"直播间:【{bilibili_live_rooms[room_id]}】打卡失败,打卡时间:【{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}】"
|
| 92 |
-
)
|
| 93 |
bilibili_logger.error(room_msg)
|
| 94 |
msg.append(room_msg)
|
| 95 |
|
|
|
|
| 70 |
for room_id in list(bilibili_live_rooms.keys()):
|
| 71 |
await page.goto(f"{bilibili_live_url}/{str(room_id)}")
|
| 72 |
# 输入框选择 xpath 绝对定位
|
| 73 |
+
input_box = page.locator(
|
| 74 |
"xpath=/html/body/div[3]/main/div[1]/section[1]/div[3]/div[12]/div/div[2]/div[2]/textarea",
|
| 75 |
)
|
| 76 |
# 输入内容
|
| 77 |
await input_box.fill("1")
|
| 78 |
# 发送按钮
|
| 79 |
+
send_button = page.locator(
|
| 80 |
"xpath=/html/body/div[3]/main/div[1]/section[1]/div[3]/div[12]/div/div[3]/div/button/span"
|
| 81 |
)
|
| 82 |
if await send_button.is_visible():
|
| 83 |
# 点击发送按钮
|
| 84 |
await send_button.click()
|
| 85 |
+
room_msg = f"直播间:【{bilibili_live_rooms[room_id]}】打卡成功,打卡时间:【{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}】"
|
|
|
|
|
|
|
| 86 |
bilibili_logger.info(room_msg)
|
| 87 |
else:
|
| 88 |
+
room_msg = f"直播间:【{bilibili_live_rooms[room_id]}】打卡失败,打卡时间:【{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}】"
|
|
|
|
|
|
|
| 89 |
bilibili_logger.error(room_msg)
|
| 90 |
msg.append(room_msg)
|
| 91 |
|
utils.py
CHANGED
|
@@ -97,7 +97,9 @@ def get_pi_ip(host: str) -> str:
|
|
| 97 |
|
| 98 |
|
| 99 |
# gotify 推送
|
| 100 |
-
def push_msg(
|
|
|
|
|
|
|
| 101 |
gotify_ip = get_pi_ip(gotify_host)
|
| 102 |
url = f"http://{gotify_ip}:{gotify_port}/message?token={gotify_token}"
|
| 103 |
data = {
|
|
@@ -117,7 +119,9 @@ async def get_bilibili_live_rooms_from_pi() -> dict:
|
|
| 117 |
sql = f"SELECT room_id, username FROM live_rooms"
|
| 118 |
pool = await get_aiomysql_instance()
|
| 119 |
data = await pool.query(sql)
|
| 120 |
-
bilibili_live_rooms =
|
|
|
|
|
|
|
| 121 |
return bilibili_live_rooms
|
| 122 |
|
| 123 |
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
# gotify 推送
|
| 100 |
+
def push_msg(
|
| 101 |
+
title: str = "无标题", message: str = "无内容", img_url: str = gotify_img
|
| 102 |
+
) -> dict:
|
| 103 |
gotify_ip = get_pi_ip(gotify_host)
|
| 104 |
url = f"http://{gotify_ip}:{gotify_port}/message?token={gotify_token}"
|
| 105 |
data = {
|
|
|
|
| 119 |
sql = f"SELECT room_id, username FROM live_rooms"
|
| 120 |
pool = await get_aiomysql_instance()
|
| 121 |
data = await pool.query(sql)
|
| 122 |
+
bilibili_live_rooms = {}
|
| 123 |
+
for d in data:
|
| 124 |
+
bilibili_live_rooms[d["room_id"]] = d["username"]
|
| 125 |
return bilibili_live_rooms
|
| 126 |
|
| 127 |
|