From f94a61e9a80e9523244ed7b36bf68472875be3f7 Mon Sep 17 00:00:00 2001 From: PinLin Date: Wed, 23 Aug 2017 15:33:38 +0800 Subject: [PATCH] reduce connections to kcoj --- access.py | 2 +- interface.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/access.py b/access.py index 879987e..5675720 100644 --- a/access.py +++ b/access.py @@ -27,7 +27,7 @@ class kuser_api: soup = BeautifulSoup(response.text, 'html.parser') return soup.find('a').get_text().strip() == '線上考試' except requests.exceptions.Timeout: - return True + return None # list all questions, deadline and hand-in status def list_questions(self): diff --git a/interface.py b/interface.py index 57ce158..268c258 100644 --- a/interface.py +++ b/interface.py @@ -78,20 +78,25 @@ class kuser: self.bot.sendMessage(self.chat_id, "哇...登入失敗,讓我們重新開始一次", reply_markup=ReplyKeyboardRemove()) self.press_username() - def check_online(self): + def check_online(self): # edit self.status = '正常使用' - if self.api.login_kcoj(self.username, self.password) == None: + result = self.api.check_online() + if result == None: self.question = '題外' - self.bot.sendMessage(self.chat_id, "郭老網站離線中!", + self.bot.sendMessage(self.chat_id, "郭老 Online Judge 離線中!", reply_markup=ReplyKeyboardMarkup(keyboard=[ ["主畫面🏠"] ], resize_keyboard=True)) return False - elif self.api.check_online() == True: + elif result == True: return True else: - self.fail_login() - return False + self.api.login_kcoj(self.username, self.password) + if self.api.check_online() == False: + self.fail_login() + return False + else: + return True def logout_system(self): self.status = '正常使用'