Issues (4)

ck_www2nzz.py (1 issue)

1
# -*- coding: utf-8 -*-
2
"""
3
cron: 12 13 * * *
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 WWW2nzz:
16
    def __init__(self, check_items):
17
        self.check_items = check_items
18
19
    @staticmethod
20
    def sign(session):
21
        response = session.get("http://www.2nzz.com/index.php", verify=False)
22
        formhash = re.findall(
23
            r'<input type="hidden" name="formhash" value="(.*?)"', response.text
24
        )[0]
25
        data = {
26
            "formhash": formhash,
27
            "qdxq": "kx",
28
            "qdmode": "2",
29
            "todaysay": "",
30
            "fastreply": "0",
31
        }
32
        params = (
33
            ("id", "dsu_paulsign:sign"),
34
            ("operation", "qiandao"),
35
            ("infloat", "1"),
36
            ("sign_as", "1"),
37
            ("inajax", "1"),
38
        )
39
        response = session.post(
40
            "http://www.2nzz.com/plugin.php", data, params=params, verify=False
41
        )
42
43
        user_resp = session.get(url="http://www.2nzz.com/home.php")
44
        uid = re.findall(r"uid=(\d+)\"", user_resp.text)
45
        uid = uid[0] if uid else "未获取到 UID"
46
47
        if "您今天已经签到过了或者签到时间还未开始" in response.text:
48
            return f"用户信息: {uid}\n签到信息: 您今天已经签到过了或者签到时间还未开始"
49
50
        check_msg = re.findall(r"<div class=\"c\">(.*?)</div>", response.text, re.S)
51
        check_msg = check_msg[0].strip() if check_msg else "签到失败"
52
53
        return f"用户信息: {uid}\n签到信息: {check_msg}"
54
55 View Code Duplication
    def main(self):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
56
        msg_all = ""
57
        for check_item in self.check_items:
58
            cookie = {
59
                item.split("=")[0]: item.split("=")[1]
60
                for item in check_item.get("cookie").split("; ")
61
            }
62
            session = requests.session()
63
            session.cookies.update(cookie)
64
            session.headers.update(
65
                {
66
                    "Origin": "http://www.2nzz.com",
67
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
68
                    "AppleWebKit/537.36 (KHTML, like Gecko) "
69
                    "Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.74",
70
                    "Accept": "text/html,application/xhtml+xml,application/xml;"
71
                    "q=0.9,image/webp,image/apng,*/*;"
72
                    "q=0.8,application/signed-exchange;v=b3;q=0.9",
73
                    "Referer": "http://www.2nzz.com/index.php",
74
                    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
75
                }
76
            )
77
            msg = self.sign(session)
78
            msg_all += msg + "\n\n"
79
        return msg_all
80
81
82
if __name__ == "__main__":
83
    _data = get_data()
84
    _check_items = _data.get("WWW2NZZ", [])
85
    result = WWW2nzz(check_items=_check_items).main()
86
    send("咔叽网单", result)
87