new URL support

This commit is contained in:
2018-05-12 13:55:08 +08:00
parent 40e72a1c66
commit 3ce0543ca8
2 changed files with 10 additions and 10 deletions

View File

@ -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"

18
kcoj.py
View File

@ -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')},