From 3ce0543ca8410efa59882b6868d55cb5ccf93bfe Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Sat, 12 May 2018 13:55:08 +0800 Subject: [PATCH] new URL support --- config.py | 2 +- kcoj.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index 58f82ec..d468ad0 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,5 @@ # KCOJ's URL -URL = "http://140.124.184.228:8080/Exam" # The Great KCOJ +URL = "https://140.124.184.228/Exam" # The Great KCOJ # KCOJ_bot's Detail TOKEN = "" NAME = "@kcoj_bot" \ No newline at end of file diff --git a/kcoj.py b/kcoj.py index cc86969..6ec6d33 100644 --- a/kcoj.py +++ b/kcoj.py @@ -12,14 +12,14 @@ class KCOJ: payload = {'name': username, 'passwd': password, 'rdoCourse': course} - return self.session.post(self.url + '/Login', data=payload, timeout=0.5) + return self.session.post(self.url + '/Login', data=payload, timeout=0.5, verify=False) except requests.exceptions.Timeout: return None # check online status def check_online(self): try: - response = self.session.get(self.url + '/TopMenu', timeout=0.5) + response = self.session.get(self.url + '/TopMenu', timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') return soup.find('a').get_text().strip() == '線上考試' except requests.exceptions.Timeout: @@ -29,7 +29,7 @@ class KCOJ: def list_questions(self): try: questions = {} - response = self.session.get(self.url + '/HomeworkBoard', timeout=0.5) + response = self.session.get(self.url + '/HomeworkBoard', timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') for tag in soup.find_all('tr'): if tag.find('a') == None: @@ -48,7 +48,7 @@ class KCOJ: # show the content of the question def show_question(self, number): try: - response = self.session.get(self.url + '/showHomework', params={'hwId': number}, timeout=0.5) + response = self.session.get(self.url + '/showHomework', params={'hwId': number}, timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') raw = soup.find('body').get_text().replace('繳交作業', '').strip() content = '' @@ -62,7 +62,7 @@ class KCOJ: def list_passers(self, number): try: passers = [] - response = self.session.get(self.url + '/success.jsp', params={'HW_ID': number}, timeout=0.5) + response = self.session.get(self.url + '/success.jsp', params={'HW_ID': number}, timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') for tr in soup.find_all('tr'): passer = tr.get_text().replace('\n', '').strip() @@ -76,7 +76,7 @@ class KCOJ: def list_results(self, number, username): try: results = [] - response = self.session.get(self.url + '/CheckResult.jsp', params={'questionID': number, 'studentID': username}, timeout=0.5) + response = self.session.get(self.url + '/CheckResult.jsp', params={'questionID': number, 'studentID': username}, timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') for tr in soup.find_all('tr'): td = tr.find('td') @@ -91,7 +91,7 @@ class KCOJ: try: payload = {'pass': password, 'submit': 'sumit'} - response = self.session.post(self.url + '/changePasswd', data=payload, timeout=0.5) + response = self.session.post(self.url + '/changePasswd', data=payload, timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') return str(soup.find('body')).split()[-2].strip() == 'Success' except requests.exceptions.Timeout: @@ -100,7 +100,7 @@ class KCOJ: # delete the answer of the question def delete_answer(self, number): try: - response = self.session.get(self.url + '/delHw', params={'title': number}, timeout=0.5) + response = self.session.get(self.url + '/delHw', params={'title': number}, timeout=0.5, verify=False) soup = BeautifulSoup(response.text, 'html.parser') return soup.find('body').get_text().replace('\n', '').strip() == 'delete success' except requests.exceptions.Timeout: @@ -109,7 +109,7 @@ class KCOJ: # hand in a answer def upload_answer(self, number, file_path): try: - self.session.get(self.url + '/upLoadHw', params={'hwId': number}, timeout=0.5) + self.session.get(self.url + '/upLoadHw', params={'hwId': number}, timeout=0.5, verify=False) response = self.session.post(self.url + '/upLoadFile', data={'FileDesc': 'Send from kcoj_bot'}, files={'hwFile': open(file_path, 'rb')},