新鲜的,运行了半天时间。
关于飞书的使用:
自己建立一个飞书群,置顶,并且在群里添加机器人,获取到机器人的推送链接填入下面即可。
使用飞书是因为tg需要梯子,我的路由不是istore os,没法一直挂梯子。使用邮箱除非使用对应的官方邮箱app,不然收信有延迟。
import requests
import time
import json
from bs4 import BeautifulSoup
import re
# ================== 配置 ==================
FEISHU_WEBHOOK = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxx"
# =========================================
def send_feishu_alert(msg: str):
"""发送飞书文本消息"""
try:
resp = requests.post(
FEISHU_WEBHOOK,
json={"msg_type": "text", "content": {"text": msg}},
headers={"Content-Type": "application/json; charset=utf-8"},
timeout=10
)
print("✅ 飞书通知发送成功" if resp.status_code == 200 else f"❌ 飞书失败: {resp.text}")
except Exception as e:
print(f"❌ 飞书异常: {e}")
def extract_stock_lines(html_text: str):
"""
从 heyunidc.cn/cart 页面提取所有“库存X”行
返回: ['库存0', '库存0', ...]
"""
lines = html_text.splitlines()
stock_lines = []
for line in lines:
line = line.strip()
if re.fullmatch(r'库存\d+', line): # 精确匹配“库存”+数字
stock_lines.append(line)
return stock_lines
def find_cart(count:int):
# 哪个活动就替换哪个活动的链接
url = 'https://www.heyunidc.cn/cart'
response = requests.get(url=url, timeout=10)
soup = BeautifulSoup(response.text,'html.parser')
soup = soup.find_all('p',{'class':'stock-info'})
aim = soup[count-1].get_text()
#print(aim)
print(f'[ooo]监听')
if aim != '库存0':
print('补货啦')
send_feishu_alert(f'核云补货啦{aim}')
else:
print(aim+'\n')
# total += 1
# 每隔10秒监听一次
# time.sleep(30)
# 第几个板块就填几
find_cart(3)
正文结束