Code refactoring and optimization: remove duplicate code, simplify grade processing logic, and improve code readability and maintainability.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
from pprint import pprint
|
||||
from zfn_api import Client
|
||||
|
||||
|
||||
def login(url, username, password):
|
||||
cookies = {}
|
||||
base_url = url
|
||||
raspisanie = []
|
||||
ignore_type = []
|
||||
detail_category_type = []
|
||||
timeout = 5
|
||||
|
||||
student_client = Client(
|
||||
cookies=cookies,
|
||||
base_url=base_url,
|
||||
raspisanie=raspisanie,
|
||||
ignore_type=ignore_type,
|
||||
detail_category_type=detail_category_type,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
if cookies == {}:
|
||||
lgn = student_client.login(username, password)
|
||||
if lgn["code"] == 1001:
|
||||
verify_data = lgn["data"]
|
||||
with open(os.path.abspath("kaptcha.png"), "wb") as pic:
|
||||
pic.write(base64.b64decode(verify_data.pop("kaptcha_pic")))
|
||||
verify_data["kaptcha"] = input("输入验证码:")
|
||||
ret = student_client.login_with_kaptcha(**verify_data)
|
||||
if ret["code"] != 1000:
|
||||
pprint(ret)
|
||||
sys.exit()
|
||||
pprint(ret)
|
||||
elif lgn["code"] != 1000:
|
||||
pprint(lgn)
|
||||
sys.exit()
|
||||
|
||||
return student_client
|
||||
Reference in New Issue
Block a user