【Python】iKuuu青龙自动签到脚本
前言
基于青龙面板编写的iKuuu每日自动签到脚本,请提前安装好青龙面板
特性说明:
多账户支持:自动读取环境变量中的多个账户信息
智能域名更新:自动检测官网域名变更并更新脚本
备用域名切换:主域名不可用时自动尝试备用域名
异常处理:单个账户失败不影响其他账户执行
结果通知:通过青龙内置通知服务推送聚合签到结果
代码
# -*- coding: utf-8 -*
'''
定时自定义
1 1 1 1 1 iKuuu.py
new Env('iKuuu签到');
'''
import requests
import re
import json
import os
import datetime
import urllib.parse
# 初始域名(自动更新逻辑保留)
ikun_host = "ikuuu.one" # 自动更新于2025-04-29 13:08:20
backup_hosts = ["ikuuu.one", "ikuuu.pw", "ikuuu.me"] # 备用域名列表
def get_latest_ikun_host():
test_url = f"https://{ikun_host}/"
try:
response = requests.get(test_url, timeout=10)
if response.status_code == 200:
if "官网域名已更改" in response.text or "Domain deprecated" in response.text:
print("检测到域名变更通知,正在提取新域名...")
h2_matches = re.findall(r'<h2>.*?(?:域名|domain)[::]\s*([a-zA-Z0-9.-]+)</h2>', response.text)
if h2_matches:
return h2_matches[0]
js_matches = re.findall(r'https?://([a-zA-Z0-9.-]+)/auth/login', response.text)
if js_matches:
return js_matches[0]
fallback_match = re.search(r'(?:域名|domain)[::]\s*([a-zA-Z0-9.-]+)', response.text)
if fallback_match:
return fallback_match.group(1)
print("⚠️ 检测到域名变更但无法提取新域名")
return None
else:
print("✅ 当前域名正常")
return None
except Exception as e:
print(f"域名检测异常: {e}")
return None
def update_self_host(new_host):
script_path = os.path.abspath(__file__)
with open(script_path, "r", encoding="utf-8") as f:
lines = f.readlines()
updated = False
for i, line in enumerate(lines):
if line.strip().startswith("ikun_host = "):
lines[i] = f'ikun_host = "{new_host}" # 自动更新于{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\n'
updated = True
break
if updated:
with open(script_path, "w", encoding="utf-8") as f:
f.writelines(lines)
print(f"✅ 脚本已更新至域名: {new_host}")
return True
else:
print("⚠️ 域名更新失败")
return False
def test_host_reachable(host):
try:
response = requests.get(f"https://{host}/", timeout=10)
return response.status_code == 200
except:
return False
def ikuuu_signin(email, password):
params = {'email': email, 'passwd': password, 'code': ''}
login_url = f'https://{ikun_host}/auth/login'
try:
# 登录请求
login_res = requests.post(login_url, data=params, timeout=15)
if login_res.status_code != 200:
return False, f"登录失败(状态码{login_res.status_code})"
login_data = login_res.json()
if login_data.get('ret') != 1:
return False, f"登录失败:{login_data.get('msg', '未知错误')}"
# 执行签到
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})"
checkin_data = checkin_res.json()
if checkin_data.get('ret') == 1:
return True, f"成功 | {checkin_data.get('msg', '')}"
else:
return False, f"签到失败:{checkin_data.get('msg', '未知错误')}"
except json.JSONDecodeError:
return False, "响应解析失败"
except requests.exceptions.Timeout:
return False, "请求超时"
except Exception as e:
return False, f"请求异常:{str(e)}"
def send_bark_notification(results, bark_url):
title = "iKuuu签到通知"
body = []
for res in results:
status = "✅" if res['success'] else "❌"
body.append(f"{status} {res['email']}: {res['message']}")
body_str = "\n".join(body)
title_encoded = urllib.parse.quote(title)
body_encoded = urllib.parse.quote(body_str)
bark_url = f"{bark_url}/{title_encoded}/{body_encoded}"
try:
res = requests.get(bark_url, timeout=10)
print(f"Bark通知发送状态:{res.status_code}")
except Exception as e:
print(f"Bark通知发送失败: {e}")
if __name__ == "__main__":
# ==================== 域名更新逻辑 ====================
print(f"当前域名: {ikun_host}")
latest_host = get_latest_ikun_host()
if latest_host:
print(f"检测到新域名: {latest_host}")
if update_self_host(latest_host):
ikun_host = latest_host
# ==================== 域名可用性检查 ====================
if not test_host_reachable(ikun_host):
print("主域名不可用,尝试备用域名...")
found = False
for host in backup_hosts:
if test_host_reachable(host):
ikun_host = host
print(f"切换到备用域名: {ikun_host}")
found = True
break
if not found:
print("❌ 所有域名均不可用")
exit(1)
# ==================== 账户处理 ====================
accounts = []
account_str = os.getenv('IKUUU_ACCOUNTS')
if not account_str:
print("❌ 未找到环境变量 IKUUU_ACCOUNTS")
exit(1)
for line in account_str.strip().splitlines():
if ':' in line:
email, pwd = line.split(':', 1)
accounts.append((email.strip(), pwd.strip()))
else:
print(f"⚠️ 忽略无效账户行: {line}")
if not accounts:
print("❌ 未找到有效账户")
exit(1)
# ==================== 执行签到 ====================
results = []
for email, pwd in accounts:
print(f"\n处理账户: {email}")
success, msg = ikuuu_signin(email, pwd)
results.append({'email': email, 'success': success, 'message': msg})
print(f"结果: {'成功' if success else '失败'} - {msg}")
# ==================== 结果通知 ====================
bark_url = os.getenv('BARK_URL')
if bark_url:
print("\n发送Bark通知...")
send_bark_notification(results, bark_url)
else:
print("\n未配置BARK_URL,跳过通知")
# ==================== 本地结果输出 ====================
print("\n签到结果汇总:")
for res in results:
print(f"邮箱: {res['email']}")
print(f"状态: {'成功' if res['success'] else '失败'}")
print(f"详情: {res['message']}\n{'-'*40}")
使用
环境变量配置(青龙面板),在「环境变量」里创建
IKUUU_ACCOUNTS
:多个账户用换行分隔,格式为邮箱:密码
user1@example.com:password1 user2@example.org:password2
配置推送通知(青龙面板),在「配置文件」中的
config.sh
中根据提示配置通知服务。将上述代码复制保存到记事本,并且重命名为
iKuuu.py
。打开青龙面板后台,「脚本管理」→「+」→「本地文件」,将保存的
iKuuu.py
上传后点击「确定」。添加定时任务。「定时任务」→「创建任务」,可自定义「名称」,「命令/脚本」固定为task iKuuu.py,「定时类型」选择常规定时,「定时规则」填写0 0 1 * * ?(每天凌晨一点执行)。
通知示例:
✅ user1@example.com: 成功 | 你获得了 294 MB流量 ❌ user2@example.org: 签到失败:您似乎已经签到过了...
日志输出:
每个账户的执行结果会在控制台详细输出
最终汇总结果通过内置通知模块推送(根据自己需求进行配置)
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果