Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
perf: 适配logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Windsland52 committed Oct 11, 2024
1 parent 8ac8ac5 commit 183e499
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions getToken.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion refreshToken.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 8 additions & 11 deletions sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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']
Expand All @@ -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']}")
Expand All @@ -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)
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)
5 changes: 3 additions & 2 deletions signMoYu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import json
import logging

def signMoYu(devcode=None, token=None):
url = "https://herobox.yingxiong.com:25362/user/signIn"
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 183e499

Please sign in to comment.