From 96ab3ab2f586be54e6af367fc0bbbbbd8ee13926 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sun, 28 Jul 2024 00:24:41 +0700 Subject: fix handle connection problem --- main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 89b9e6b..66eadf7 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,9 @@ bot = Bot() def getScore(): - downloadCsv() + isSuccess = downloadCsv() + if not isSuccess: + return -1 myScore = readCSV() try: myScore = 100 * float(myScore) @@ -27,7 +29,8 @@ def processMessages(messages): if 'update' in (msg.lower() for msg in messages): logger.info("EXPLICIT SCORE UPDATE REQUESTED") score = getScore() - bot.sendMessage(f"Score leantime bulan ini = {score}%") + msg = f"Score leantime bulan ini = {score}%" if score >= 0 else "Connection problem with report dashboard" + bot.sendMessage(msg) @repeat(every().day.at("09:00")) @@ -37,8 +40,8 @@ def main(): weekday = today.weekday() if weekday not in [5, 6]: # jangan ganggu aku di akhir pekan myScore = getScore() - msg = f"Leantime score = {myScore}%. Jangan lupa isi leantime" - if (17 <= today.day <= 24) and myScore < 70: # seminggu sebelumnya udah ngingetin + msg = f"Leantime score = {myScore}%. Jangan lupa isi leantime" if myScore >= 0 else "Connection problem with report dashboard" + if (17 <= today.day <= 24) and (0 <= myScore < 70): # seminggu sebelumnya udah ngingetin msg = f'WARNING! SEKARANG UDAH TANGGAL {today.day}, SCORE LEANTIME MASIH {myScore}%' bot.sendMessage(msg) -- cgit v1.2.3-70-g09d2