| Conditions | 7 |
| Total Lines | 61 |
| Code Lines | 52 |
| 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", |
||
| 44 | headers=headers, |
||
| 45 | json=login_data, |
||
| 46 | ).json() |
||
| 47 | if not login_res["success"]: |
||
| 48 | return "登录失败" |
||
| 49 | data = login_res["data"] |
||
| 50 | except json.decoder.JSONDecodeError: |
||
| 51 | return "登录请求失败" |
||
| 52 | |||
| 53 | headers["_HAIDILAO_APP_TOKEN"] = data["token"] |
||
| 54 | headers["ReqType"] = "APPH5" |
||
| 55 | headers[ |
||
| 56 | "Referer" |
||
| 57 | ] = f'{url}app-sign-in/?SignInToken={data["token"]}&source=MiniApp' |
||
| 58 | |||
| 59 | try: |
||
| 60 | signin_res = requests.post( |
||
| 61 | f"{url}activity/wxapp/signin/signin", |
||
| 62 | headers=headers, |
||
| 63 | json={"signinSource": "MiniApp"}, |
||
| 64 | ).json() |
||
| 65 | if "请勿重复操作" in signin_res["msg"]: |
||
| 66 | return "今日签到过了" |
||
| 67 | except json.decoder.JSONDecodeError: |
||
| 68 | return "签到请求失败" |
||
| 69 | |||
| 70 | try: |
||
| 71 | fragment_res = requests.post( |
||
| 72 | f"{url}activity/wxapp/signin/queryFragment", headers=headers |
||
| 73 | ).json() |
||
| 74 | if fragment_res["success"]: |
||
| 75 | return ( |
||
| 76 | f'账号:{data["name"]} 签到成功\n' f'碎片余额:{fragment_res["data"]["total"]}' |
||
| 77 | ) |
||
| 78 | except json.decoder.JSONDecodeError: |
||
| 79 | return "查询请求失败" |
||
| 80 | |||
| 96 |