Passed
Push — master ( a1e615...c41d1a )
by Leon
02:06
created

ck_hlx.HLX.sign()   B

Complexity

Conditions 5

Size

Total Lines 43
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 35
nop 2
dl 0
loc 43
rs 8.5733
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 30 7 * * *
4
new Env('葫芦侠');
5
"""
6
7
import hashlib
8
import json
9
10
import requests
11
from bs4 import BeautifulSoup
12
13
from notify_mtr import send
14
from utils import get_data
15
16
17
class HLX:
18
    def __init__(self, check_items):
19
        self.check_items = check_items
20
21
    def md5(self, password):
22
        m = hashlib.md5()
23
        b = password.encode(encoding="utf-8")
24
        m.update(b)
25
        password_md5 = m.hexdigest()
26
        return password_md5
27
28
    def login(self, username, password):
29
        password_md5 = self.md5(password)
30
        url = "https://floor.huluxia.com/account/login/IOS/4.0"
31
        headers = {
32
            "Content-Type": "application/x-www-form-urlencoded",
33
        }
34
        data = {
35
            "account": username,
36
            "deviceCode": "",
37
            "device_code": "",
38
            "login_type": "2",
39
            "password": password_md5,
40
        }
41
        response = requests.post(url=url, data=data, headers=headers)
42
        key = json.loads(response.text)["_key"]
43
        nick = json.loads(response.text)["user"]["nick"]
44
        userID = json.loads(response.text)["user"]["userID"]
45
        msg = "[+]用户:" + nick + " userID:" + str(userID)
46
        return key, nick, userID, msg
47
48
    def get_level(self, userID, key):
49
        url = f"http://floor.huluxia.com/view/level?viewUserID={userID}&_key={key}"
50
        response = requests.post(url=url)
51
        soup = BeautifulSoup(response.text, "html.parser")  # 解析html页面
52
        level = soup.select(".lev_li_forth span")  # 筛选经验值
53
        msg = (
54
            "[+]当前经验值:"
55
            + level[0].string
56
            + "\n[+]距离下一等级:"
57
            + level[1].string
58
            + " 还需:"
59
            + level[2].string
60
            + " 经验"
61
        )
62
        return msg
63
64
    def sign(self, key):
65
        # 获取所有板块 url
66
        url = "https://floor.huluxia.com/category/forum/list/IOS/1.0"
67
        # 获取所有板块下的内容 url
68
        ura = "https://floor.huluxia.com/category/forum/list/all/IOS/1.0"
69
        # 签到板块 url
70
        urs = "https://floor.huluxia.com/user/signin/IOS/1.1"
71
        # 获取所有板块
72
        categoryforum = requests.post(url).json()["categoryforum"]
73
        result = ""
74
        for i in categoryforum:
75
            # 获取所有板块下的内容
76
            categories = requests.post(url=ura, data={"fum_id": i["id"]}).json()[
77
                "categories"
78
            ]
79
            for cat in categories:
80
                headers = {
81
                    "Host": "floor.huluxia.com",
82
                    "Content-Type": "application/x-www-form-urlencoded",
83
                    "Connection": "keep-alive",
84
                    "Accept": "*/*",
85
                    "User-Agent": "Floor/1.3.0 (iPhone; iOS 15.3; Scale/3.00)",
86
                    "Accept-Language": "zh-Hans-CN;q=1",
87
                    "Content-Length": "304",
88
                    "Accept-Encoding": "gzip, deflate, br",
89
                }
90
                res = requests.post(
91
                    url=urs,
92
                    data={"_key": key, "cat_id": cat["categoryID"]},
93
                    headers=headers,
94
                ).json()
95
                msg = res["msg"]
96
                status = res["status"]
97
                if status == 0:
98
                    result += "\n[+]" + cat["title"] + " 签到失败 错误原因:" + msg
99
                elif status == 1:
100
                    result += (
101
                        "\n[+]"
102
                        + cat["title"]
103
                        + " 签到成功 获得经验:"
104
                        + str(res["experienceVal"])
105
                    )
106
        return result
107
108
    def main(self):
109
        msg_all = ""
110
        for check_item in self.check_items:
111
            username = check_item.get("username")
112
            password = check_item.get("password")
113
            key, nick, userID, login_msg = self.login(username, password)
114
            level_msg = self.get_level(userID, key)
115
            sign_msg = self.sign(key)
116
            msg = login_msg + "\n" + level_msg + sign_msg
117
            msg_all += msg + "\n\n"
118
        return msg_all
119
120
121
def start():
122
    data = get_data()
123
    _check_items = data.get("HLX", [])
124
    res = HLX(check_items=_check_items).main()
125
    send("葫芦侠", res)
126
127
128
if __name__ == "__main__":
129
    start()
130