new URL support
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
# KCOJ's URL
|
# 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
|
# KCOJ_bot's Detail
|
||||||
TOKEN = ""
|
TOKEN = ""
|
||||||
NAME = "@kcoj_bot"
|
NAME = "@kcoj_bot"
|
18
kcoj.py
18
kcoj.py
@ -12,14 +12,14 @@ class KCOJ:
|
|||||||
payload = {'name': username,
|
payload = {'name': username,
|
||||||
'passwd': password,
|
'passwd': password,
|
||||||
'rdoCourse': course}
|
'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:
|
except requests.exceptions.Timeout:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# check online status
|
# check online status
|
||||||
def check_online(self):
|
def check_online(self):
|
||||||
try:
|
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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
return soup.find('a').get_text().strip() == '線上考試'
|
return soup.find('a').get_text().strip() == '線上考試'
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
@ -29,7 +29,7 @@ class KCOJ:
|
|||||||
def list_questions(self):
|
def list_questions(self):
|
||||||
try:
|
try:
|
||||||
questions = {}
|
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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
for tag in soup.find_all('tr'):
|
for tag in soup.find_all('tr'):
|
||||||
if tag.find('a') == None:
|
if tag.find('a') == None:
|
||||||
@ -48,7 +48,7 @@ class KCOJ:
|
|||||||
# show the content of the question
|
# show the content of the question
|
||||||
def show_question(self, number):
|
def show_question(self, number):
|
||||||
try:
|
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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
raw = soup.find('body').get_text().replace('繳交作業', '').strip()
|
raw = soup.find('body').get_text().replace('繳交作業', '').strip()
|
||||||
content = ''
|
content = ''
|
||||||
@ -62,7 +62,7 @@ class KCOJ:
|
|||||||
def list_passers(self, number):
|
def list_passers(self, number):
|
||||||
try:
|
try:
|
||||||
passers = []
|
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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
for tr in soup.find_all('tr'):
|
for tr in soup.find_all('tr'):
|
||||||
passer = tr.get_text().replace('\n', '').strip()
|
passer = tr.get_text().replace('\n', '').strip()
|
||||||
@ -76,7 +76,7 @@ class KCOJ:
|
|||||||
def list_results(self, number, username):
|
def list_results(self, number, username):
|
||||||
try:
|
try:
|
||||||
results = []
|
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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
for tr in soup.find_all('tr'):
|
for tr in soup.find_all('tr'):
|
||||||
td = tr.find('td')
|
td = tr.find('td')
|
||||||
@ -91,7 +91,7 @@ class KCOJ:
|
|||||||
try:
|
try:
|
||||||
payload = {'pass': password,
|
payload = {'pass': password,
|
||||||
'submit': 'sumit'}
|
'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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
return str(soup.find('body')).split()[-2].strip() == 'Success'
|
return str(soup.find('body')).split()[-2].strip() == 'Success'
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
@ -100,7 +100,7 @@ class KCOJ:
|
|||||||
# delete the answer of the question
|
# delete the answer of the question
|
||||||
def delete_answer(self, number):
|
def delete_answer(self, number):
|
||||||
try:
|
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')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
return soup.find('body').get_text().replace('\n', '').strip() == 'delete success'
|
return soup.find('body').get_text().replace('\n', '').strip() == 'delete success'
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
@ -109,7 +109,7 @@ class KCOJ:
|
|||||||
# hand in a answer
|
# hand in a answer
|
||||||
def upload_answer(self, number, file_path):
|
def upload_answer(self, number, file_path):
|
||||||
try:
|
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',
|
response = self.session.post(self.url + '/upLoadFile',
|
||||||
data={'FileDesc': 'Send from kcoj_bot'},
|
data={'FileDesc': 'Send from kcoj_bot'},
|
||||||
files={'hwFile': open(file_path, 'rb')},
|
files={'hwFile': open(file_path, 'rb')},
|
||||||
|
Reference in New Issue
Block a user