Conditions | 7 |
Total Lines | 61 |
Code Lines | 51 |
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 -*- |
||
19 | @staticmethod |
||
20 | def checkin(openid, uid): |
||
21 | headers = { |
||
22 | "Host": "superapp-public.kiwa-tech.com", |
||
23 | "Content-Length": "115", |
||
24 | "appId": "15", |
||
25 | "content-type": "application/json", |
||
26 | "Accept-Encoding": "gzip,compress,br,deflate", |
||
27 | "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) " |
||
28 | "AppleWebKit/605.1.15 (KHTML, like Gecko) " |
||
29 | "Mobile MicroMessenger NetType/4G Language/en miniProgram", |
||
30 | "Referer": "https://servicewechat.com/wx1ddeb67115f30d1a/14/page-frame.html", |
||
31 | } |
||
32 | login_data = { |
||
33 | "openId": openid, |
||
34 | "country": "CN", |
||
35 | "uid": uid, |
||
36 | "type": 1, |
||
37 | "codeType": 1, |
||
38 | } |
||
39 | url = "https://superapp-public.kiwa-tech.com/" |
||
40 | |||
41 | try: |
||
42 | login_res = requests.post( |
||
43 | f"{url}login/thirdCommLogin", headers=headers, json=login_data |
||
44 | ).json() |
||
45 | if not login_res["success"]: |
||
46 | return "登录失败" |
||
47 | data = login_res["data"] |
||
48 | except json.decoder.JSONDecodeError: |
||
49 | return "登录请求失败" |
||
50 | |||
51 | headers["_HAIDILAO_APP_TOKEN"] = data["token"] |
||
52 | headers["ReqType"] = "APPH5" |
||
53 | headers[ |
||
54 | "Referer" |
||
55 | ] = f'{url}app-sign-in/?SignInToken={data["token"]}&source=MiniApp' |
||
56 | |||
57 | try: |
||
58 | signin_res = requests.post( |
||
59 | f"{url}activity/wxapp/signin/signin", |
||
60 | headers=headers, |
||
61 | json={"signinSource": "MiniApp"}, |
||
62 | ).json() |
||
63 | if "请勿重复操作" in signin_res["msg"]: |
||
64 | return "今日签到过了" |
||
65 | except json.decoder.JSONDecodeError: |
||
66 | return "签到请求失败" |
||
67 | |||
68 | try: |
||
69 | fragment_res = requests.post( |
||
70 | f"{url}activity/wxapp/signin/queryFragment", headers=headers |
||
71 | ).json() |
||
72 | if fragment_res["success"]: |
||
73 | return ( |
||
74 | f'账号:{data["name"]} 签到成功\n' f'碎片余额:{fragment_res["data"]["total"]}' |
||
75 | ) |
||
76 | except json.decoder.JSONDecodeError: |
||
77 | return "查询请求失败" |
||
78 | |||
79 | return "未知错误" |
||
80 | |||
96 |