ck_smzdm.Smzdm.sign()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 38
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nop 1
dl 0
loc 38
rs 9.45
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 51 9 * * *
4
new Env('什么值得买');
5
"""
6
7
from urllib.parse import quote, unquote
8
9
import requests
10
11
from notify_mtr import send
12
from utils import get_data
13
14
15
class Smzdm:
16
    def __init__(self, check_items):
17
        self.check_items = check_items
18
19
    @staticmethod
20
    def sign(session):
21
        try:
22
            current = session.get(
23
                url="https://zhiyou.smzdm.com/user/info/jsonp_get_current"
24
            ).json()
25
            if current["checkin"]["has_checkin"]:
26
                msg = (
27
                    f"用户信息: {current.get('nickname', '')}\n"
28
                    f"目前积分: {current.get('point', '')}\n"
29
                    f"经验值: {current.get('exp', '')}\n"
30
                    f"金币: {current.get('gold', '')}\n"
31
                    f"碎银子: {current.get('silver', '')}\n"
32
                    f"威望: {current.get('prestige', '')}\n"
33
                    f"等级: {current.get('level', '')}\n"
34
                    f"已经签到: {current.get('checkin', {}).get('daily_checkin_num', '')} 天"
35
                )
36
            else:
37
                data = (
38
                    session.get(
39
                        url="https://zhiyou.smzdm.com/user/checkin/jsonp_checkin"
40
                    )
41
                    .json()
42
                    .get("data", {})
43
                )
44
                msg = (
45
                    f"用户信息: {current.get('nickname', '')}\n"
46
                    f"目前积分: {data.get('point', '')}\n"
47
                    f"增加积分: {data.get('add_point', '')}\n"
48
                    f"经验值: {data.get('exp', '')}\n"
49
                    f"金币: {data.get('gold', '')}\n"
50
                    f"威望: {data.get('prestige', '')}\n"
51
                    f"等级: {data.get('rank', '')}\n"
52
                    f"已经签到: {data.get('checkin_num', {})} 天"
53
                )
54
        except Exception as e:
55
            msg = f"签到状态: 签到失败\n错误信息: {e},请重新获取 cookie"
56
        return msg
57
58
    def main(self):
59
        msg_all = ""
60
61
        for check_item in self.check_items:
62
            cookie = {
63
                item.split("=")[0]: quote(unquote(item.split("=")[1]))
64
                for item in check_item.get("cookie").split("; ")
65
                if item.split("=")[0] == "sess"
66
            }
67
            session = requests.session()
68
            session.cookies.update(cookie)
69
            session.headers.update(
70
                {
71
                    "Accept": "*/*",
72
                    "Accept-Encoding": "gzip, deflate, br",
73
                    "Accept-Language": "zh-CN,zh;q=0.9",
74
                    "Connection": "keep-alive",
75
                    "Host": "zhiyou.smzdm.com",
76
                    "Referer": "https://www.smzdm.com/",
77
                    "Sec-Fetch-Dest": "script",
78
                    "Sec-Fetch-Mode": "no-cors",
79
                    "Sec-Fetch-Site": "same-site",
80
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
81
                    "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
82
                }
83
            )
84
            msg = self.sign(session)
85
            msg_all += msg + "\n\n"
86
        return msg_all
87
88
89
if __name__ == "__main__":
90
    _data = get_data()
91
    _check_items = _data.get("SMZDM", [])
92
    result = Smzdm(check_items=_check_items).main()
93
    send("什么值得买", result)
94