ck_hlx   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 86
dl 0
loc 113
rs 10
c 0
b 0
f 0
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A HLX.md5() 0 6 1
A HLX.__init__() 0 2 1
A HLX.main() 0 11 2
B HLX.sign() 0 34 5
A HLX.get_level() 0 8 1
A HLX.login() 0 17 1

1 Function

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