Conditions | 3 |
Total Lines | 51 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
21 | @staticmethod |
||
22 | def sign(cookie): |
||
23 | try: |
||
24 | ts = int(round(time.time() * 1000)) |
||
25 | url = 'https://user-api.smzdm.com/robot/token' |
||
26 | headers = { |
||
27 | 'Host': 'user-api.smzdm.com', |
||
28 | 'Content-Type': 'application/x-www-form-urlencoded', |
||
29 | 'Cookie': f'{cookie}', |
||
30 | 'User-Agent': 'smzdm_android_V10.4.1 rv:841 (22021211RC;Android12;zh)smzdmapp', |
||
31 | } |
||
32 | data = { |
||
33 | "f": "android", |
||
34 | "v": "10.4.1", |
||
35 | "weixin": 1, |
||
36 | "time": ts, |
||
37 | "sign": hashlib.md5(bytes(f'f=android&time={ts}&v=10.4.1&weixin=1&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC', encoding='utf-8')).hexdigest().upper() |
||
38 | } |
||
39 | html = requests.post(url=url, headers=headers, data=data) |
||
40 | res = html.json() |
||
41 | token = res['data']['token'] |
||
42 | |||
43 | Timestamp = int(round(time.time() * 1000)) |
||
44 | data = { |
||
45 | "f": "android", |
||
46 | "v": "10.4.1", |
||
47 | "sk": "ierkM0OZZbsuBKLoAgQ6OJneLMXBQXmzX+LXkNTuKch8Ui2jGlahuFyWIzBiDq/L", |
||
48 | "weixin": 1, |
||
49 | "time": Timestamp, |
||
50 | "token": token, |
||
51 | "sign": hashlib.md5(bytes(f'f=android&sk=ierkM0OZZbsuBKLoAgQ6OJneLMXBQXmzX+LXkNTuKch8Ui2jGlahuFyWIzBiDq/L&time={Timestamp}&token={token}&v=10.4.1&weixin=1&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC', encoding='utf-8')).hexdigest().upper() |
||
52 | } |
||
53 | url = 'https://user-api.smzdm.com/checkin' |
||
54 | url2 = 'https://user-api.smzdm.com/checkin/all_reward' |
||
55 | headers = { |
||
56 | 'Host': 'user-api.smzdm.com', |
||
57 | 'Content-Type': 'application/x-www-form-urlencoded', |
||
58 | 'Cookie': f'{cookie}', |
||
59 | 'User-Agent': 'smzdm_android_V10.4.1 rv:841 (22021211RC;Android12;zh)smzdmapp', |
||
60 | } |
||
61 | html = requests.post(url=url, headers=headers, data=data) |
||
62 | html2 = requests.post(url=url2, headers=headers, data=data) |
||
63 | res = json.loads(html.text) |
||
64 | res2 = json.loads(html2.text) |
||
65 | if res2['error_code'] == '0': |
||
66 | msg = res2["title"] + res2["sub_title"] |
||
67 | else: |
||
68 | msg = res['error_msg'] |
||
69 | except Exception as e: |
||
70 | msg = f"签到状态: 签到失败\n错误信息: {e},请重新获取 cookie" |
||
71 | return msg |
||
72 | |||
87 |