增加剩余流量显示
This commit is contained in:
parent
1827ac84c0
commit
f7ed38bea5
@ -40,7 +40,13 @@ task ik_signin 0 0 1 * * ?
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 2025-06-01
|
||||
- 增加剩余流量显示
|
||||
|
||||
---
|
||||
|
||||
### 2025-05-31
|
||||
|
||||
- 初始版本发布
|
||||
- 实现基本签到功能
|
||||
- 添加域名自动检测和更新机制
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*
|
||||
'''
|
||||
定时自定义
|
||||
0 0 1 * * ? iKuuu.py
|
||||
0 0 1 * * ?
|
||||
new Env('iKuuu签到');
|
||||
'''
|
||||
import requests
|
||||
@ -11,7 +11,8 @@ import os
|
||||
import datetime
|
||||
import urllib.parse
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
# 添加青龙脚本根目录到Python路径
|
||||
QL_SCRIPTS_DIR = '/ql/scripts' # 青龙脚本默认目录
|
||||
@ -91,6 +92,49 @@ def test_host_reachable(host):
|
||||
except:
|
||||
return False
|
||||
|
||||
def get_remaining_flow(cookies):
|
||||
"""获取用户剩余流量信息"""
|
||||
user_url = f'https://{ikun_host}/user'
|
||||
try:
|
||||
# 获取用户页面
|
||||
user_page = requests.get(user_url, cookies=cookies, timeout=15)
|
||||
if user_page.status_code != 200:
|
||||
return "获取流量失败", "状态码: " + str(user_page.status_code)
|
||||
|
||||
# 使用BeautifulSoup解析HTML
|
||||
soup = BeautifulSoup(user_page.text, 'html.parser')
|
||||
|
||||
# 查找包含剩余流量的卡片
|
||||
flow_cards = soup.find_all('div', class_='card card-statistic-2')
|
||||
for card in flow_cards:
|
||||
h4_tag = card.find('h4')
|
||||
if h4_tag and '剩余流量' in h4_tag.text:
|
||||
# 查找流量数值
|
||||
counter_span = card.find('span', class_='counter')
|
||||
if counter_span:
|
||||
flow_value = counter_span.text.strip()
|
||||
|
||||
# 查找流量单位
|
||||
unit_text = ""
|
||||
next_sibling = counter_span.next_sibling
|
||||
if next_sibling:
|
||||
unit_text = next_sibling.strip()
|
||||
|
||||
return flow_value, unit_text
|
||||
|
||||
# 如果没有找到,尝试其他方式
|
||||
flow_div = soup.find('div', string='剩余流量')
|
||||
if flow_div:
|
||||
parent_div = flow_div.find_parent('div', class_='card-body')
|
||||
if parent_div:
|
||||
flow_text = parent_div.get_text(strip=True).replace('剩余流量', '')
|
||||
return flow_text.split()[0], flow_text.split()[1] if len(flow_text.split()) > 1 else ""
|
||||
|
||||
return "未找到", "流量信息"
|
||||
|
||||
except Exception as e:
|
||||
return "流量获取异常", str(e)
|
||||
|
||||
def ikuuu_signin(email, password):
|
||||
params = {'email': email, 'passwd': password, 'code': ''}
|
||||
login_url = f'https://{ikun_host}/auth/login'
|
||||
@ -98,34 +142,39 @@ def ikuuu_signin(email, password):
|
||||
# 登录请求
|
||||
login_res = requests.post(login_url, data=params, timeout=15)
|
||||
if login_res.status_code != 200:
|
||||
return False, f"登录失败(状态码{login_res.status_code})"
|
||||
flow_value, flow_unit = "登录失败", "无法获取"
|
||||
return False, f"登录失败(状态码{login_res.status_code})", flow_value, flow_unit
|
||||
|
||||
login_data = login_res.json()
|
||||
if login_data.get('ret') != 1:
|
||||
return False, f"登录失败:{login_data.get('msg', '未知错误')}"
|
||||
flow_value, flow_unit = "登录失败", "无法获取"
|
||||
return False, f"登录失败:{login_data.get('msg', '未知错误')}", flow_value, flow_unit
|
||||
|
||||
# 获取用户剩余流量
|
||||
cookies = login_res.cookies
|
||||
flow_value, flow_unit = get_remaining_flow(cookies)
|
||||
|
||||
# 执行签到
|
||||
cookies = login_res.cookies
|
||||
checkin_res = requests.post(f'https://{ikun_host}/user/checkin', cookies=cookies, timeout=15)
|
||||
if checkin_res.status_code != 200:
|
||||
return False, f"签到失败(状态码{checkin_res.status_code})"
|
||||
return False, f"签到失败(状态码{checkin_res.status_code})", flow_value, flow_unit
|
||||
|
||||
checkin_data = checkin_res.json()
|
||||
if checkin_data.get('ret') == 1:
|
||||
return True, f"成功 | {checkin_data.get('msg', '')}"
|
||||
return True, f"成功 | {checkin_data.get('msg', '')}", flow_value, flow_unit
|
||||
else:
|
||||
return False, f"签到失败:{checkin_data.get('msg', '未知错误')}"
|
||||
return False, f"签到失败:{checkin_data.get('msg', '未知错误')}", flow_value, flow_unit
|
||||
except json.JSONDecodeError:
|
||||
return False, "响应解析失败"
|
||||
return False, "响应解析失败", "未知", "未知"
|
||||
except requests.exceptions.Timeout:
|
||||
return False, "请求超时"
|
||||
return False, "请求超时", "未知", "未知"
|
||||
except Exception as e:
|
||||
return False, f"请求异常:{str(e)}"
|
||||
return False, f"请求异常:{str(e)}", "未知", "未知"
|
||||
|
||||
def send_qinglong_notification(results):
|
||||
"""
|
||||
使用青龙面板内置通知模块发送通知
|
||||
需要青龙面板已配置config.sh内的通知渠道(如钉钉、企业微信等)
|
||||
使用青龙面板内置通知系统发送通知
|
||||
需要青龙面板已配置通知渠道(如钉钉、企业微信等)
|
||||
"""
|
||||
title = "iKuuu签到通知"
|
||||
|
||||
@ -143,6 +192,7 @@ def send_qinglong_notification(results):
|
||||
message.append(f"{index}. {res['email']}")
|
||||
message.append(f" 状态:{status}")
|
||||
message.append(f" 详情:{res['message']}")
|
||||
message.append(f" 剩余流量:{res['flow_value']} {res['flow_unit']}")
|
||||
message.append("--------------------------------")
|
||||
|
||||
# 添加统计信息
|
||||
@ -200,9 +250,19 @@ if __name__ == "__main__":
|
||||
results = []
|
||||
for email, pwd in accounts:
|
||||
print(f"\n处理账户: {email}")
|
||||
success, msg = ikuuu_signin(email, pwd)
|
||||
results.append({'email': email, 'success': success, 'message': msg})
|
||||
success, msg, flow_value, flow_unit = ikuuu_signin(email, pwd)
|
||||
results.append({
|
||||
'email': email,
|
||||
'success': success,
|
||||
'message': msg,
|
||||
'flow_value': flow_value,
|
||||
'flow_unit': flow_unit
|
||||
})
|
||||
print(f"结果: {'成功' if success else '失败'} - {msg}")
|
||||
print(f"剩余流量: {flow_value} {flow_unit}")
|
||||
|
||||
# 账户间延迟防止请求过快
|
||||
time.sleep(1)
|
||||
|
||||
# ==================== 结果通知 ====================
|
||||
print("\n正在发送通知...")
|
||||
@ -213,4 +273,5 @@ if __name__ == "__main__":
|
||||
for res in results:
|
||||
print(f"邮箱: {res['email']}")
|
||||
print(f"状态: {'成功' if res['success'] else '失败'}")
|
||||
print(f"详情: {res['message']}\n{'-'*40}")
|
||||
print(f"详情: {res['message']}")
|
||||
print(f"剩余流量: {res['flow_value']} {res['flow_unit']}\n{'-'*40}")
|
Loading…
Reference in New Issue
Block a user