diff --git a/kcoj.py b/kcoj.py index 4f48c77..687e119 100644 --- a/kcoj.py +++ b/kcoj.py @@ -12,14 +12,14 @@ class KCOJ: payload = {'name': username, 'passwd': password, 'rdoCourse': 1} - return self._session.post(self._url.URL + '/Login', data=payload, timeout=0.5) + return self._session.post(self._url + '/Login', data=payload, timeout=0.5) except requests.exceptions.Timeout: return None # check online status def check_online(self): try: - response = self._session.get(self._url.URL + '/TopMenu', timeout=0.5) + response = self._session.get(self._url + '/TopMenu', timeout=0.5) 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.URL + '/HomeworkBoard', timeout=0.5) + response = self._session.get(self._url + '/HomeworkBoard', timeout=0.5) soup = BeautifulSoup(response.text, 'html.parser') for tag in soup.find_all('tr'): if tag.find('a') == None: @@ -47,7 +47,7 @@ class KCOJ: # show the content of the question def show_question(self, number): try: - response = self._session.get(self._url.URL + '/showHomework', params={'hwId': number}, timeout=0.5) + response = self._session.get(self._url + '/showHomework', params={'hwId': number}, timeout=0.5) soup = BeautifulSoup(response.text, 'html.parser') raw = soup.find('body').get_text().replace('繳交作業', '').strip() content = '' @@ -61,7 +61,7 @@ class KCOJ: def list_passers(self, number): try: passers = [] - response = self._session.get(self._url.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) soup = BeautifulSoup(response.text, 'html.parser') for tr in soup.find_all('tr'): passer = tr.get_text().replace('\n', '').strip() @@ -75,7 +75,7 @@ class KCOJ: def list_results(self, number, username): try: results = [] - response = self._session.get(self._url.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) soup = BeautifulSoup(response.text, 'html.parser') for tr in soup.find_all('tr'): td = tr.find('td') @@ -90,7 +90,7 @@ class KCOJ: try: payload = {'pass': password, 'submit': 'sumit'} - response = self._session.post(self._url.URL + '/changePasswd', data=payload, timeout=0.5) + response = self._session.post(self._url + '/changePasswd', data=payload, timeout=0.5) soup = BeautifulSoup(response.text, 'html.parser') return str(soup.find('body')).split()[-2].strip() == 'Success' except requests.exceptions.Timeout: @@ -99,7 +99,7 @@ class KCOJ: # delete the answer of the question def delete_answer(self, number): try: - response = self._session.get(self._url.URL + '/delHw', params={'title': number}, timeout=0.5) + response = self._session.get(self._url + '/delHw', params={'title': number}, timeout=0.5) soup = BeautifulSoup(response.text, 'html.parser') return soup.find('body').get_text().replace('\n', '').strip() == 'delete success' except requests.exceptions.Timeout: @@ -108,8 +108,8 @@ class KCOJ: # hand in a answer def upload_answer(self, number, file_path): try: - self._session.get(self._url.URL + '/upLoadHw', params={'hwId': number}, timeout=0.5) - response = self._session.post(self._url.URL + '/upLoadFile', + self._session.get(self._url + '/upLoadHw', params={'hwId': number}, timeout=0.5) + response = self._session.post(self._url + '/upLoadFile', data={'FileDesc': 'Send from kcoj_bot'}, files={'hwFile': open(file_path, 'rb')}, timeout=0.5)