diff --git a/access.py b/access.py index 050f3c5..d62e6e8 100644 --- a/access.py +++ b/access.py @@ -6,15 +6,13 @@ from bs4 import BeautifulSoup # configurations import config -class kuser: - def __init__(self, un='', pw=''): - self.username = un - self.password = pw +class kuser_api: + def __init__(self): self.session = requests.Session() # login kCOJ - def login(self): - payload = {'name': self.username, - 'passwd': self.password, + def login(self, username, password): + payload = {'name': username, + 'passwd': password, 'rdoCourse': 1} return self.session.post(config.URL + '/Login', data=payload) # check online status @@ -33,8 +31,9 @@ class kuser: else: number = tag.find('a').get_text() deadline = tag.find_all('td')[3].get_text() - status = tag.find_all('td')[5].get_text() - questions[number] = (deadline, status) + submit = "期限已到" if tag.find_all('td')[4].get_text().strip() == "期限已過" else "期限未到" + status = tag.find_all('td')[5].get_text().strip() + questions[number] = (deadline, submit, status) return questions # show the content of the question def show_question(self, number): @@ -44,6 +43,7 @@ class kuser: content = content.replace('
\n', '') content = content.replace('\n\n', '').replace('\n', '') content = content.replace('', '') + content = content.replace(' 繳交作業 ', '') content = content.replace('', '').replace('' + content + '
', parse_mode='HTML')
+ me = kuser()
+ if str(chat_id) in users:
+ me = users[str(chat_id)]
else:
- bot.sendMessage(chat_id, '```\n' + str(msg) + '\n```', parse_mode='Markdown')
+ users[str(chat_id)] = me
+
+ if content_type == 'text':
+ command = split_cmd(msg['text'])
+
+ if me.status == 1:
+ me.status = 2
+ me.username = msg['text']
+ bot.sendMessage(chat_id, "請輸入您的密碼:")
+ elif me.status == 2:
+ me.password = msg['text']
+ bot.sendMessage(chat_id, "登入中...")
+ if me.test_login(chat_id) == True:
+ me.display_main(chat_id)
+ elif command[0] == '/start':
+ if me.status == 0:
+ me.status = 1
+ bot.sendMessage(chat_id, "是初次見面的朋友呢,設定一下吧!\n")
+ time.sleep(0.6)
+ bot.sendMessage(chat_id, "請輸入您的學號:")
+ else:
+ if me.test_login(chat_id) == True:
+ me.display_main(chat_id)
+
+ else:
+ bot.sendMessage(chat_id, "我不是來看這些的。")
-users = {}
bot = telepot.Bot(config.TOKEN)
-MessageLoop(bot, {'chat': on_chat}).run_as_thread()
+MessageLoop(bot, on_chat).run_as_thread()
# for debug
def main():
- users[config.DEBUG_ID] = access.kuser(config.DEBUG_USER, config.DEBUG_PSWD)
-
+ pass
+ # over 20MB will stop this bot!
+ # bot.download_file('BQADBQADHQADPAc5VEZQejGkM9C4Ag', '../wa.txt')
main()
+
while True:
time.sleep(10)
\ No newline at end of file