<br />
<br />
安装青龙脚本
直接在应用商店安装即可
再安装所需环境:
参考链接:https://club.fnnas.com/forum.php?mod=viewthread&tid=3002
设置环境变量名:PV_COOKIE
获取cookie填入变量内
青龙签到脚本文件
import os
import notify # 不可删除
import httpx
import logging
import asyncio
from datetime import datetime, timedelta
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def get_cookie_from_env():
"""从环境变量中读取 Cookie """
cookie_string = os.environ.get('PV_COOKIE', '')
if not cookie_string:
try:
from qlpanel.some_module import get_env_variable
cookie_string = get_env_variable('PV_COOKIE')
except ImportError:
logging.error("未找到环境变量 PV_COOKIE,请确保已正确设置。")
raise ValueError("未找到 Cookie")
return cookie_string
async def sign_in(sign_in_url, cookie_string):
"""执行签到操作"""
if not cookie_string:
logging.error("未找到 Cookie,无法进行签到。")
return "未找到 Cookie,无法进行签到。"
headers = {'Cookie': cookie_string}
async with httpx.AsyncClient() as client:
try:
response = await client.get(sign_in_url, headers=headers)
# 检查响应状态码
if response.status_code == 200:
if "您今天已经打过卡了,请勿重复操作!" in response.text:
logging.info("今天已经签到过了,无需重复操作!")
return "今天已经签到过了,无需重复操作!"
elif "恭喜您,打卡成功!" in response.text:
logging.info("恭喜您,打卡成功!")
return "恭喜您,打卡成功!"
else:
logging.warning("未知响应内容,可能签到失败。")
logging.debug("响应内容: %s", response.text)
return "未知响应内容,可能签到失败。"
else:
logging.error("打卡失败!")
logging.error("状态码: %s", response.status_code)
logging.error("响应内容: %s", response.text)
return f"打卡失败!状态码: {response.status_code}"
except httpx.RequestError as e:
logging.error("请求异常: %s", e)
return f"请求异常: {e}"
async def send_notification(summary_message):
"""异步发送通知"""
try:
notify.send("飞牛OS论坛签到情况", summary_message)
except Exception as e:
logging.error("通知发送失败: %s", e)
async def wait_until(target_time):
"""等待直到指定时间"""
now = datetime.now()
wait_time = (target_time - now).total_seconds()
if wait_time > 0:
logging.info(f"当前时间: {now}, 等待到目标时间: {target_time}")
await asyncio.sleep(wait_time)
return target_time
async def main():
# 固定签到地址
sign_in_url = "https://club.fnnas.com/plugin.php?id=zqlj_sign&sign=a33ba82c"
try:
# 编译代码
cookie_string = get_cookie_from_env()
logging.info("读取到的 Cookie: %s", cookie_string)
except ValueError as e:
logging.error(e)
return
# 确定执行时间
now = datetime.now()
target_time = now.replace(hour=0, minute=0, second=30, microsecond=900000)
if target_time < now:
target_time += timedelta(days=1)
# 等待到指定时间
start_time = await wait_until(target_time)
# 执行签到
sign_result = await sign_in(sign_in_url, cookie_string)
sign_time = datetime.now()
# 计算脚本运行时间
run_time = (sign_time - start_time).total_seconds()
# 格式化签到时间,精确到毫秒
sign_time_str = sign_time.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
# 格式化脚本运行时间,精确到毫秒
run_time_str = f"{run_time * 1000:.3f} 毫秒"
# 生成通知内容
summary_message = f"签到结果:{sign_result}\n签到时间:{sign_time_str}\n脚本运行时间:{run_time_str}"
# 发送请求
await send_notification(summary_message)
if __name__ == "__main__":
asyncio.run(main())
:loveliness: 注意:签到脚本是固定时间运行的,意思是,现在跑起来不会立即签到,而是到了91行代码设置的时间才会发送签到时间。
(hour=0, minute=0, second=30, microsecond=900000)
是0点0分30秒900毫秒时执行签到命令
设置青龙通知,脚本签到完成即可收到通知内容 |