| 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 -*- |
||
| 20 | @staticmethod |
||
| 21 | def sign(cookie): |
||
| 22 | try: |
||
| 23 | ts = int(round(time.time() * 1000)) |
||
| 24 | url = 'https://user-api.smzdm.com/robot/token' |
||
| 25 | headers = { |
||
| 26 | 'Host': 'user-api.smzdm.com', |
||
| 27 | 'Content-Type': 'application/x-www-form-urlencoded', |
||
| 28 | 'Cookie': f'{cookie}', |
||
| 29 | 'User-Agent': 'smzdm_android_V10.4.1 rv:841 (22021211RC;Android12;zh)smzdmapp', |
||
| 30 | } |
||
| 31 | data = { |
||
| 32 | "f": "android", |
||
| 33 | "v": "10.4.1", |
||
| 34 | "weixin": 1, |
||
| 35 | "time": ts, |
||
| 36 | "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() |
||
| 37 | } |
||
| 38 | html = requests.post(url=url, headers=headers, data=data) |
||
| 39 | res = html.json() |
||
| 40 | token = res['data']['token'] |
||
| 41 | |||
| 42 | Timestamp = int(round(time.time() * 1000)) |
||
| 43 | data = { |
||
| 44 | "f": "android", |
||
| 45 | "v": "10.4.1", |
||
| 46 | "sk": "ierkM0OZZbsuBKLoAgQ6OJneLMXBQXmzX+LXkNTuKch8Ui2jGlahuFyWIzBiDq/L", |
||
| 47 | "weixin": 1, |
||
| 48 | "time": Timestamp, |
||
| 49 | "token": token, |
||
| 50 | "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() |
||
| 51 | } |
||
| 52 | url = 'https://user-api.smzdm.com/checkin' |
||
| 53 | url2 = 'https://user-api.smzdm.com/checkin/all_reward' |
||
| 54 | headers = { |
||
| 55 | 'Host': 'user-api.smzdm.com', |
||
| 56 | 'Content-Type': 'application/x-www-form-urlencoded', |
||
| 57 | 'Cookie': f'{cookie}', |
||
| 58 | 'User-Agent': 'smzdm_android_V10.4.1 rv:841 (22021211RC;Android12;zh)smzdmapp', |
||
| 59 | } |
||
| 60 | html = requests.post(url=url, headers=headers, data=data) |
||
| 61 | html2 = requests.post(url=url2, headers=headers, data=data) |
||
| 62 | res = json.loads(html.text) |
||
| 63 | res2 = json.loads(html2.text) |
||
| 64 | if res2['error_code'] == '0': |
||
| 65 | msg = res2["title"] + res2["sub_title"] |
||
| 66 | else: |
||
| 67 | msg = res['error_msg'] |
||
| 68 | except Exception as e: |
||
| 69 | msg = f"签到状态: 签到失败\n错误信息: {e},请重新获取 cookie" |
||
| 70 | return msg |
||
| 71 | |||
| 86 |