Issues (4)

ck_zhiyoo.py (1 issue)

1
# -*- coding: utf-8 -*-
2
"""
3
cron: 7 21 * * *
4
new Env('智友邦');
5
"""
6
7
import re
8
9
import requests
10
11
from notify_mtr import send
12
from utils import get_data
13
14
15
class Zhiyoo:
16
    def __init__(self, check_items):
17
        self.check_items = check_items
18
19
    @staticmethod
20
    def sign(session):
21
        response = session.get(
22
            url="http://bbs.zhiyoo.net/plugin.php?id=dsu_paulsign:sign", verify=False
23
        )
24
        formhash = re.findall(
25
            r'<input type="hidden" name="formhash" value="(.*?)"', response.text
26
        )[0]
27
        data = {"formhash": formhash, "qdxq": "kx"}
28
        params = (
29
            ("id", "dsu_paulsign:sign"),
30
            ("operation", "qiandao"),
31
            ("infloat", "1"),
32
            ("inajax", "1"),
33
        )
34
35
        response = session.post(
36
            url="http://bbs.zhiyoo.net/plugin.php",
37
            params=params,
38
            data=data,
39
            verify=False,
40
        )
41
        user_resp = session.get(url="http://bbs.zhiyoo.net/home.php")
42
        uid = re.findall(r"uid=(\d+)\"", user_resp.text)
43
        uid = uid[0] if uid else "未获取到 UID"
44
        if "今日已经签到" in response.text:
45
            return f"用户信息: {uid}\n签到信息: 您今日已经签到,请明天再来!"
46
47
        check_msg = re.findall(r"恭喜你签到成功!获得随机奖励 金币 (\d+) 元.", response.text, re.S)
48
        check_msg = check_msg[0].strip() if check_msg else "签到失败"
49
50
        return f"用户信息: {uid}\n签到信息: 恭喜你签到成功!获得随机奖励 金币 {check_msg} 元."
51
52 View Code Duplication
    def main(self):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
53
        msg_all = ""
54
        for check_item in self.check_items:
55
            cookie = {
56
                item.split("=")[0]: item.split("=")[1]
57
                for item in check_item.get("cookie").split("; ")
58
            }
59
60
            session = requests.session()
61
            session.cookies.update(cookie)
62
            session.headers.update(
63
                {
64
                    "Origin": "http://bbs.zhiyoo.net",
65
                    "Content-Type": "application/x-www-form-urlencoded",
66
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
67
                    "AppleWebKit/537.36 (KHTML, like Gecko) "
68
                    "Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54",
69
                    "Accept": "text/html,application/xhtml+xml,application/xml;"
70
                    "q=0.9,image/webp,image/apng,*/*;"
71
                    "q=0.8,application/signed-exchange;v=b3;q=0.9",
72
                    "Referer": "http://bbs.zhiyoo.net/plugin.php?id=dsu_paulsign:sign",
73
                    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
74
                }
75
            )
76
            msg = self.sign(session)
77
            msg_all += msg + "\n\n"
78
        return msg_all
79
80
81
if __name__ == "__main__":
82
    _data = get_data()
83
    _check_items = _data.get("ZHIYOO", [])
84
    result = Zhiyoo(check_items=_check_items).main()
85
    send("智友邦", result)
86