Untitled
unknown
python
4 years ago
3.3 kB
3
Indexable
import requests import re def lineNotifyMessage(token, msg): headers = { "Authorization": "Bearer " + token, "Content-Type" : "application/x-www-form-urlencoded" } payload = {'message': msg } r = requests.post("https://notify-api.line.me/api/notify", headers = headers, params = payload) return r.status_code class AutoSignIn(): errorCode = { "0":"成功", "1":"帳號或密碼錯誤", "2":"該帳號無此課程", "3":"點名已到期", "4":"無偵測到點名網址", "5":"HTTP Error" } def __init__(self, username, password) -> None: self.baseUrl = "https://staff.csmu.edu.tw/handler/RWDHandler22.ashx" r = requests.get("https://staff.csmu.edu.tw/Teacher/wScore22_1.aspx") session = r.cookies.get_dict()["ASP.NET_SessionId"] self.sendData = { "mode": "CheckCSMULoginUser", "Param": username + "," + password, "method": "GenQRCodeDetail", "parameters": "|Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Mobile Safari/537.36" } self.header = { "accept":"*/*", "accept-encoding":"gzip, deflate, br", "accept-language":"zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6", "cookie":"ASP.NET_SessionId=" + session, "origin":"https://staff.csmu.edu.tw", "referer":"", "sec-ch-ua":"\"Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"", "sec-ch-ua-mobile":"?0", "sec-fetch-dest":"empty", "sec-fetch-mode":"cors", "sec-fetch-site":"same-origin", "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36", "x-requested-with":"XMLHttpRequest" } def send(self, url): self.header["referer"] = url code = url.split("=")[1] self.sendData["parameters"] = code + "|Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Mobile Safari/537.36" print("Code=", code) r = requests.post(self.baseUrl, data=self.sendData, headers=self.header) #r = requests.post(self.baseUrl, headers=self.header) status = r.text print(r.request) if(r.status_code != 200): return 5 print("Url=", self.baseUrl) print("Requests header = ", r.headers) print(r.text) if(status == "N,登入失敗。"): return 1 elif(status == "N,查無此課程點名主檔。"): return 2 elif(status == "N,點名時效已過。"): return 3 return 0 @staticmethod def doUrlRegex(text): if(not "staff.csmu.edu.tw/Teacher/wScore22_1.aspx" in text): return 4 extractUrl = re.findall("staff\.csmu\.edu\.tw\/Teacher\/wScore22_1\.aspx\?ParamQRCODE=[0-9]+", text)[0] print(extractUrl) return "https://" + extractUrl
Editor is loading...