From 183e499d5efedfb0c374e3bfbe8935c91e869158 Mon Sep 17 00:00:00 2001 From: Windsland52 <86581225+Windsland52@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:21:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=80=82=E9=85=8Dlogger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- getToken.py | 3 +-- refreshToken.py | 2 +- sign.py | 19 ++++++++----------- signMoYu.py | 5 +++-- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/getToken.py b/getToken.py index 4532a6a..e0ab1e1 100644 --- a/getToken.py +++ b/getToken.py @@ -44,11 +44,10 @@ def getToken(phone, smsCode, devcode): if json.loads(response.text)["code"] == 200 and json.loads(response.text)["success"] == True: logging.info("登录成功") - logging.info("token:", json.loads(response.text)["data"]["token"]) return json.loads(response.text)["data"]["token"], json.loads(response.text)["data"]["refreshToken"] else: logging.error("登录失败", json.loads(response.text)["msg"]) - return None, None + return "", "" if __name__ == '__main__': with open("config.json", "r") as f: diff --git a/refreshToken.py b/refreshToken.py index 304b81a..5d62781 100644 --- a/refreshToken.py +++ b/refreshToken.py @@ -41,7 +41,7 @@ def refresh_token(token=None, devcode=None, refreshToken=None): try: config['token'] = response_dict['data']['token'] except: - logging.error("刷新token失败") + logging.error(f"刷新token失败,{response_dict['msg']}") exit() with open('config.json', 'w', encoding='utf-8') as f: json.dump(config, f, ensure_ascii=False, indent=4) diff --git a/sign.py b/sign.py index b3e2cd0..c02f795 100644 --- a/sign.py +++ b/sign.py @@ -5,7 +5,7 @@ import logging -def sign(token=None): +def sign(token=None,devcode=None, refreshToken=None): url = "https://herobox.yingxiong.com:26723/encourage/signin/signin" headers = { @@ -33,8 +33,8 @@ def sign(token=None): with open('show.json', 'r', encoding='utf-8') as f: show_dict = json.load(f) if show_dict['data']['roleInfo'] == {}: - logging.error("登录信息已失效,进行token刷新!") - refresh_token() + logging.warning("登录信息已失效,进行token刷新!") + refresh_token(token, devcode, refreshToken) return False signinTime = show_dict['data']['signinTime'] periodID = show_dict['data']['period']['id'] @@ -49,12 +49,7 @@ def sign(token=None): } response = requests.post(url, headers=headers, data=data) - # print(response.text) - # try: - # with open('response.json', 'w', encoding='utf-8') as f: - # json.dump(response.json(), f, ensure_ascii=False, indent=4) - # except: - # print("写入response.json失败!") + if response.status_code == 200: if response.json()['code'] == 200: logging.info(f"签到成功!获得{show_dict['data']['dayAward'][signinTime]['awardName']}") @@ -68,11 +63,13 @@ def sign(token=None): # print(f"sendContinueAward类型为{type(response.json()['data']['sendContinueAward'])}") // bool logging.info(f"累计签到{signinTimeNow}天,获得{continueAwardList}") elif response.json()['code'] == 711: - logging.info(f"今天已经签到过了!") + logging.info(f"签到失败!今天已经签到过了!") elif response.json()['code'] == 10000: logging.error(f"签到失败!{response.json()['msg']}") return True if __name__ == '__main__': token = json.load(open('config.json', 'r', encoding='utf-8'))['token'] - sign(token) \ No newline at end of file + devcode = json.load(open('config.json', 'r', encoding='utf-8'))['devcode'] + refreshToken = json.load(open('config.json', 'r', encoding='utf-8'))['refreshToken'] + sign(token, devcode, refreshToken) \ No newline at end of file diff --git a/signMoYu.py b/signMoYu.py index c7a1a69..b347e07 100644 --- a/signMoYu.py +++ b/signMoYu.py @@ -1,5 +1,6 @@ import requests import json +import logging def signMoYu(devcode=None, token=None): url = "https://herobox.yingxiong.com:25362/user/signIn" @@ -29,9 +30,9 @@ def signMoYu(devcode=None, token=None): response = requests.post(url, headers=headers, data=data) if response.json()['code'] == 200: - print("签到成功!") + logging.info(f"签到成功!{response.json()['msg']}") else: - print(f"签到失败!{response.json()['msg']}") + logging.info(f"签到失败!{response.json()['msg']}") if __name__ == '__main__': token = json.load(open('config.json'))['token']