diff --git a/login.py b/login.py new file mode 100644 index 0000000..ce98a14 --- /dev/null +++ b/login.py @@ -0,0 +1,113 @@ +import os +import configparser +import requests + +class Ipgw_login(object): + def __init__(self): + self.stu_ID = "" + self.stu_password = "" + self.login_url = 'https://pass.neu.edu.cn/tpass/login?service=http://ipgw.neu.edu.cn/srun_portal_sso?ac_id={}' + + + def config(self,Fname="config.ini"): + # 获取当前的路径 + filepath = os.path.split(os.path.realpath(__file__))[0] + filename = os.path.join(filepath, Fname) + # print(filename) + + # 获取账号,密码 + conf = configparser.ConfigParser() + conf.read(filename) + + self.stu_ID = conf.get("info","StudentID") + self.stu_password = conf.get("info","password") + + # print(self.stu_ID,self.stu_password) + + + def login_with_acid(self,ac_id): + # 访问统一登录获取lt + session = requests.Session() + get_pass_page = session.get(self.login_url.format(ac_id)) + if get_pass_page.status_code != 200: + return False, f'访问pass.neu.edu.cn失败,状态码:{get_pass_page.status_code}' + # text = ...\r\n\t\t\t + text = get_pass_page.text + + # 获取lt (login token) + target = '\r\n\t\t\t + half = text[text.index(target) + len(target):] + # lt = LT-29360-**********-tpass + lt = half[:half.index('"')] + + # 获取execution + target = '