2025年11月16日星期日

看雪论坛任务脚本

1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/Bg6shY若失效,可用地址

1.购买服务器

阿里云:

服务器购买地址

https://t.aliyun.com/U/Bg6shY

若失效,可用地址

https://www.aliyun.com/daily-act/ecs/activity_selection?source=5176.29345612&userCode=49hts92d

腾讯云:

https://curl.qcloud.com/wJpWmSfU

若失效,可用地址

https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console

华为云

https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905

2.部署教程

2024年最新青龙面板跑脚本教程(一)持续更新中

3.代码如下

#!/usr/bin/env python3# -*- coding: utf-8 -*-
import requestsimport jsonimport osimport sysfrom datetime import datetimeimport urllib3
# 禁用SSL警告urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# 状态文件路径STATUS_FILE = "status/status_kanxue.json"
def load_today_status():    """加载今日签到状态"""    if not os.path.exists(STATUS_FILE):        return False
    try:        with open(STATUS_FILE, 'r', encoding='utf-8'as f:            data = f.read().strip()            if not data:                return False            status = json.loads(data)            # 检查是否是今天的记录            today = datetime.now().strftime('%Y-%m-%d')            if status.get('date') == today and status.get('success'):                print(f" 今日({today})已成功签到,跳过本次运行")                return True    except Exception as e:        print(f" 读取状态文件失败: {e}")
    return False
def save_today_status(success, message=""):    """保存今日签到状态"""    today = datetime.now().strftime('%Y-%m-%d')    status = {        'date': today,        'success': success,        'message': message,        'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S')    }
    # 确保status目录存在    os.makedirs(os.path.dirname(STATUS_FILE), exist_ok=True)
    try:        with open(STATUS_FILE, 'w', encoding='utf-8'as f:            f.write(json.dumps(status, ensure_ascii=False, indent=2))        print(f" 状态已保存: {status}")    except Exception as e:        print(f" 保存状态失败: {e}")
def check_cookie(cookie):    """检查Cookie格式"""    if not cookie or not len(cookie):        error_msg = " 错误: Cookie为空"        print(error_msg)        return False, error_msg
    pairs = cookie.split(';')    for pair_str in pairs:        pair = pair_str.strip()        if pair and '=' not in pair:            error_msg = f" Cookie格式错误: {pair}"            print(error_msg)            return False, error_msg
    print(" Cookie检查通过")    return True"Cookie格式正确"
def kanxue_checkin():    """看雪论坛签到主函数"""
    # 从环境变量读取配置    cookie = os.environ.get('KANXUE_COOKIE')    pushplus_token = os.environ.get('PUSHPLUS_TOKEN')
    if not cookie:        error_msg = " 错误: 未找到KANXUE_COOKIE环境变量"        print(error_msg)        save_today_status(False, error_msg)        return False
    # 检查Cookie格式    cookie_valid, cookie_msg = check_cookie(cookie)    if not cookie_valid:        save_today_status(False, cookie_msg)        return False
    url = "https://bbs.kanxue.com/user-signin.htm"
    headers = {        'User-Agent''HD1910(Android/7.1.2) (pediy.UNICFBC0DD/1.0.5) Weex/0.26.0 720x1280',        'Cookie': cookie,        'Connection''keep-alive',        'Accept''*/*'    }
    print("=" * 60)    print(f" 看雪论坛自动签到 - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")    print("=" * 60)    print(f" 目标地址: {url}")    print(f" Cookie长度: {len(cookie)} 字符")
    try:        response = requests.post(            url,            headers=headers,            timeout=30,            verify=False        )
        print(f" HTTP状态码: {response.status_code}")
        if response.status_code == 200:            try:                data = response.json()                print(f" 响应数据: {json.dumps(data, ensure_ascii=False, indent=2)}")
                message = data.get('message''')                code = data.get('code')
                if code == 0 or message == '您今日已签到成功':                    if code == 0:                        success_msg = f"签到成功!获得{message}雪币"                        print(f" {success_msg}")                    else:                        success_msg = "今日已签到,无需重复签到"                        print(f" {success_msg}")
                    # 发送推送通知                    if pushplus_token:                        send_pushplus(pushplus_token, success_msg, code)                    else:                        print(" 未设置PUSHPLUS_TOKEN,跳过推送")
                    save_today_status(True, success_msg)                    return True                else:                    error_msg = f"签到失败: {message}"                    print(f" {error_msg}")                    save_today_status(False, error_msg)                    return False
            except json.JSONDecodeError as e:                error_msg = f"JSON解析失败: {response.text[:200]}"                print(f" {error_msg}")                save_today_status(False, error_msg)                return False        else:            error_msg = f"HTTP {response.status_code}{response.text[:200]}"            print(f" {error_msg}")            save_today_status(False, error_msg)            return False
    except requests.exceptions.Timeout:        error_msg = "请求超时"        print(f" {error_msg}")        save_today_status(False, error_msg)        return False
    except requests.exceptions.ConnectionError as e:        error_msg = f"网络连接失败: {str(e)}"        print(f" {error_msg}")        save_today_status(False, error_msg)        return False
    except Exception as e:        error_msg = f"未知错误: {type(e).__name__} - {str(e)}"        print(f" {error_msg}")        import traceback        traceback.print_exc()        save_today_status(False, error_msg)        return False
def send_pushplus(token, msg, code):    """发送PushPlus通知"""    if code == 0:        title = '看雪论坛签到成功'        content = f'签到成功,获得{msg}雪币'    else:        title = '看雪论坛签到提醒'        content = '您已签到,无需重复签到'
    data = {        "token": token,        "title": title,        "content": content,        "template""json"    }
    # 打印脱敏的推送数据(用于调试)    debug_data = data.copy()    if debug_data.get('token'):        token_str = debug_data['token']        if len(token_str) > 8:            debug_data['token'] = token_str[:4] + '*' * (len(token_str) - 8) + token_str[-4:]    print(f' 推送数据: {debug_data}')
    try:        response = requests.post(            'http://www.pushplus.plus/send',            json=data,            timeout=10        )
        if response.status_code == 200:            result = response.json()            print(f' PushPlus推送成功: {result.get("msg""未知")}')        else:            print(f' PushPlus推送失败,状态码: {response.status_code}')    except requests.exceptions.RequestException as e:        print(f' PushPlus推送异常: {str(e)}')    except Exception as e:        print(f' PushPlus推送未知错误: {str(e)}')
def main():    """主函数"""    # 检查今日是否已成功签到    if load_today_status():        print(" 今日已完成签到,无需重复运行")        sys.exit(0)
    # 执行签到    success = kanxue_checkin()
    print("=" * 60)    if success:        print(" 签到任务完成")        sys.exit(0)    else:        print(" 签到任务失败")        sys.exit(1)
if __name__ == "__main__":    main()
解析
该脚本为看雪论坛自动签到脚本。

主要作用

  1. 从环境变量读取 KANXUE_COOKIE(论坛 Cookie);

  2. 先检查今天是否已经成功签到(本地 status/status_kanxue.json 状态文件);

  3. 如果还没签到,调用 https://bbs.kanxue.com/user-signin.htm 执行签到请求;

  4. 根据接口返回内容判断:签到成功 / 已签到 / 失败;

  5. 把今日结果写入状态文件;

  6. 如果配置了 PUSHPLUS_TOKEN,通过 PushPlus 推送签到结果(成功或已签到)。

主要方法

1. load_today_status()

  • 作用:读取本地状态文件,判断 "今天是否已经签到成功过"

  • 逻辑:

    • 如果状态文件不存在、为空或不是今天的记录 → 返回 False;

    • 如果文件里标记今天 success=True → 打印"今日已成功签到,跳过",返回 True。

  • 目的:避免同一天重复给看雪接口签到、避免重复推送。

2. save_today_status(success, message="")

  • 作用:把本次签到结果写入状态文件 status/status_kanxue.json

  • 保存内容包括:

    • 日期(date)、是否成功(success)、提示消息(message)、时间戳(timestamp)。

  • 会自动创建 status 目录。

  • 方便下次运行时通过 load_today_status() 判断是否需要再跑。

3. check_cookie(cookie)

  • 作用:对从环境变量拿到的 Cookie 做一次简单格式校验。

  • 校验点:

    • 是否为空;

    • 按 ; 拆分后,每一段都要是 key=value 形式,否则当作格式错误。

  • 返回 (True/False, 错误信息/成功信息)

  • 目的:在发请求前提前发现明显错误,减少无效请求。

4. kanxue_checkin()

  • 作用看雪论坛签到的核心流程

  • 步骤:

    • 状态码 200 时尝试解析 JSON:

    • 非 200 状态码:当作 HTTP 错误;

    • code == 0:视为签到成功(打印并可推送"获得多少雪币");

    • message == '您今日已签到成功':视为"今日已签到",不算失败;

    • 其他 code/message:当作签到失败;

    • KANXUE_COOKIE(必需)

    • PUSHPLUS_TOKEN(可选)

    1. 从环境变量读取:

    2. 若 Cookie 缺失或格式错误 → 写入状态文件并返回 False;

    3. 构造移动端 UA、带 Cookie 的头;

    4. POST 请求到 https://bbs.kanxue.com/user-signin.htm

    5. 无论成功/失败,都会调用 save_today_status() 记录结果;

    6. 如果配置了 PushPlus,调用 send_pushplus() 推送消息。

  • 同时有各种异常捕获:超时、连接失败、其他异常都会记为失败并写入状态。

5. send_pushplus(token, msg, code)

  • 作用:通过 PushPlus 推送签到结果到微信。

  • 规则:

    • 标题:签到提醒

    • 内容:提示已签到无需重复

    • 标题:看雪论坛签到成功

    • 内容:带"获得多少雪币"的提示

    • code == 0(真正签到成功):

    • 非 0(一般是"已签到"场景):

  • 会对 token 做简单脱敏打印,方便调试但不泄露完整 token。

  • 发送 POST 请求到 http://www.pushplus.plus/send,并打印推送结果/错误。

6. main()

  • 作用:脚本总入口,负责"要不要签到"以及退出码。

  • 流程:

    • 如果今天已经成功签到 → 打印"今日已完成签到,无需重复运行",直接退出 0;

    1. 先调用 load_today_status()

    2. 未签到则调用 kanxue_checkin() 执行全流程;

    3. 根据返回 True / False,打印"签到任务完成/失败",并用 sys.exit(0/1) 设置进程返回值(便于Actions 判断成功或失败)。


注意

本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。


历史脚本txt文件获取>>
服务器搭建,人工服务咨询>>

没有评论:

发表评论

搭了一个小论坛,欢迎各位老板交流

点击上方蓝字关注我博主是一个理工男,非常喜欢捣鼓博客、论坛啥的,读书的时候也搭建过一个论坛,然后就没有然后了。 点击上方 蓝字 关注我 博主是一个理工男,非常喜欢捣鼓博客、论坛啥的,读书的时候也搭建过一个论坛,然后就没有然后了。 公众号只能自言自语,跟各位朋友互动情况不好。现...