fix upload answer filename

This commit is contained in:
2018-04-14 16:55:27 +08:00
parent f1420f89c8
commit 0b8980b763
2 changed files with 14 additions and 7 deletions

View File

@ -225,15 +225,22 @@ class Kuser:
["首頁🏠", "回題目📜"]
], resize_keyboard=True))
def send_answer(self, text, file_id):
def send_answer(self, text, file_id, language):
self._status = '正常使用'
# define filename
filename = self._username + self._question
if language == 'Python':
filename += '.py'
else:
filename += '.c'
if text != '':
with open(self._username + self._question + '.c', 'w') as f:
with open(filename, 'w') as f:
f.write(text)
else:
bot.download_file(file_id, self._username + self._question + '.c')
bot.download_file(file_id, filename)
self._api.delete_answer(self._question)
if self._api.upload_answer(self._question, self._username + self._question + '.c') == True:
if self._api.upload_answer(self._question, filename) == True:
bot.sendMessage(self._userid, "上傳成功",
reply_markup=ReplyKeyboardMarkup(keyboard=[
["首頁🏠", "回題目📜"],
@ -246,7 +253,7 @@ class Kuser:
["首頁🏠", "回題目📜"],
["登出🚪", "改密碼💱", "幫助📚"]
], resize_keyboard=True))
os.remove(self._username + self._question + '.c')
os.remove(filename)
def delete_answer(self):
bot.sendMessage(self._userid, "移除成功" if self._api.delete_answer(self._question) == True else "移除失敗",