def pushCode(self, code, lang, id, cid): sessionId = getSession() s = requests.Session() cookie_obj = requests.cookies.create_cookie(domain='bajton.vlo.gda.pl', name='sessionid', value=sessionId) s.cookies.set_cookie(cookie_obj) csrfget = requests.get(string_api + "profile") print("[OK]Obtained valid CSRF token:", csrfget.cookies.get_dict()["csrftoken"]) h = dict() h["X-CSRFToken"] = csrfget.cookies.get_dict()["csrftoken"] h["Content-Type"] = "application/json;charset=UTF-8" #Posting submission form if (cid == -1): #Push to public problems r = s.post(url=string_api + "submission", data='{"code": "' + code + '", "language": "' + lang + '", "problem_id": "' + id + '"}', cookies=csrfget.cookies.get_dict(), headers=h) else: #Push to contest r = s.post(url=string_api + "submission", data='{"code": "' + code + '", "language": "' + lang + '", "contest_id": "' + cid + '", "problem_id": "' + id + '"}', cookies=csrfget.cookies.get_dict(), headers=h) data = r.json() print(data)
def contestLookup(self, cid): if (self.checkContestAccess(cid)): c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get(string_api + "contest/problem?contest_id=" + cid, cookies=c) data = check.json()["data"] #find matching problem in contest for i in data: if (self.q in i["title"].lower() or self.q in i["_id"].lower()): self.results.append({ "_id": i["_id"], "id": i["id"], "title": i["title"], "cName": self.cNames[cid], "cId": cid, "status": self.states[str(i["my_status"])] })
def getCode(self, id): c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get(string_api + "submission?id=" + id, cookies=c) data = check.json()["data"]["code"] return data.replace("\n", "\\n").replace("\t", "\\t").replace("\"", '\\"')
def checkContestAccess(self, cid): print("[...]Checking contest type: " + cid) parser = ConfigParser() parser.read('props.ini') c = dict() #getting session id sessionId = getSession() c["sessionid"] = sessionId r = requests.get(string_api + "contest?id=" + cid, cookies=c) print(r) x = r.json()["data"] #print(cid,x) if (x["contest_type"] != "Password Protected"): return True else: #check contest access check = requests.get(string_api + "contest/access?contest_id=" + str(x["id"]), cookies=c) if ("true" in check.text): return True else: try: #try to authenticate to the contest parser["PASSWORDS"][str(x["id"])] csrfget = requests.get(string_api + "profile") h = dict() #obtain CSRF token h["X-CSRFToken"] = csrfget.cookies.get_dict()["csrftoken"] h["Content-Type"] = "application/json;charset=UTF-8" c["csrftoken"] = csrfget.cookies.get_dict()["csrftoken"] test = requests.post(string_api + "contest/password", headers=h, cookies=c, data='{"contest_id":"' + str(x["id"]) + '","password":"******"PASSWORDS"][str(x["id"])] + '"}') if ('true' in test.text): return True else: print("[WARN]Authentication failed for " + str(x["title"]) + ":" + test.text) except: print("[WARN]No password found for " + str(x["title"])) return False
def publicLookup(self): c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get(string_api + "problem?limit=99", cookies=c) data = check.json()["data"]["results"] #find matching problem in public problems for i in data: if (self.q in i["title"].lower() or self.q in i["_id"].lower()): self.results.append({ "_id": i["_id"], "id": i["id"], "title": i["title"], "cName": "Public problems", "cId": "-1", "status": self.states[str(i["my_status"])] })
def publicAnswersLookup(self): c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get(string_api + "submissions?myself=1&result=0&limit=250", cookies=c) data = check.json()["data"]["results"] #loop through job instances to get the latest success publish for i in data: if (self.q in i["problem"].lower()): self.results.append({ "id": str(i["id"]), "cName": "Public problems", "language": i["language"], "cId": "-1", "target": self.exclude, "pid": self.pid })
def contestAnswersLookup(self, cid): if (self.checkContestAccess(cid)): c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get( string_api + "contest_submissions?myself=1&result=0&limit=250&contest_id=" + cid, cookies=c) data = check.json()["data"]["results"] #loop through job instances to get the latest success publish for i in data: if (self.q in i["problem"].lower()): self.results.append({ "id": str(i["id"]), "cName": self.cNames[cid], "language": i["language"], "cId": cid, "target": self.exclude, "pid": self.pid })
def contestLookup(self, cid): if (self.checkContestAccess(cid)): c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get(string_api + "contest/problem?contest_id=" + cid, cookies=c) data = check.json()["data"] silent = False try: if (str(cid) not in self.parser["CACHE"]): self.parser["CACHE"][str(cid)] = "" #don't spam on first launch silent = True except KeyError: self.parser["CACHE"] = dict() self.parser["CACHE"][str(cid)] = "" autoFilled = 0 for p in data: if (str(p["id"]) not in self.parser["CACHE"][str(cid)].split(";") and p["my_status"] != 0): if (not silent): self.trayIcon.showMessage( self.cNames[cid], string_new_problem + ": " + p["title"]) if (self.config["contestMode"] == "Auto"): if (self.trySolve(cid, p["_id"], str(p["id"]))): autoFilled += 1 self.parser["CACHE"][str(cid)] += str(p["id"]) + ";" if (autoFilled > 0): self.trayIcon.showMessage( str(autoFilled) + string_autofill_success, string_autofill_desc) with open('props.ini', 'w') as configfile: self.parser.write(configfile)
def checkPublic(self): try: if ("publicCount" in self.parser["CACHE"]): last = int(self.parser["CACHE"]["publicCount"]) else: last = -1 except KeyError: self.parser["CACHE"] = dict() last = -1 print("[...]Checking public problems updates") print(last) c = dict() sessionId = getSession() c["sessionid"] = sessionId check = requests.get(string_api + "problem?limit=99", cookies=c) data = check.json()["data"]["results"] print(len(data)) autoFilled = 0 #don't spam on first launch if (last > -1): for i in range(last, len(data)): #notify only when problem is not already solved if (data[i]["my_status"] != 0): self.trayIcon.showMessage(string_new_problem, data[i]["title"]) if (self.config["publicMode"] == "Auto"): if (self.trySolve("-1", data[i]["_id"], str(data[i]["id"]))): autoFilled += 1 if (autoFilled > 0): self.trayIcon.showMessage( str(autoFilled) + string_autofill_success, string_autofill_desc) self.parser["CACHE"]["publicCount"] = str(len(data)) with open('props.ini', 'w') as configfile: self.parser.write(configfile)
{"name": "_qf__mod_attendance_student_attendance_form"})["value"] return session.post( baseURL + "/mod/attendance/attendance.php", headers={'Content-Type': "application/x-www-form-urlencoded"}, data= "sessid={sessid}&sesskey={sesskey}&mform_isexpanded_id_session={mform_isexpanded_id_session}" .format(sessid=sessid, sesskey=sessKey, mform_isexpanded_id_session=mform_isexpanded_id_session) + "&_qf__mod_attendance_student_attendance_form={qf}".format( qf=_qf__mod_attendance_student_attendance_form) + "&studentpassword={stuPassword}&status={status}".format( stuPassword=studentPassword, status=getPresentStatus(soup))) if __name__ == "__main__": username = input("username: "******"sessid: ") studentPassword = input("studentPassword: "******"id": "user-notifications"}) form_invalid_feedbacks = soup.findAll( 'div', {"class": "form-control-feedback invalid-feedback"}) print(user_notificationsTags) print(form_invalid_feedbacks)