summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2024-07-27 21:45:38 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2024-07-27 21:45:38 +0700
commit38c6f914ed61c2348014a2998d1815d959ed2871 (patch)
tree39c99a698932531ef86120cfed5b6381a20d87e7 /main.py
parente74357544064105b23fca2cd15a09c2bf16072af (diff)
upd: get score by explicit request
Diffstat (limited to 'main.py')
-rw-r--r--main.py41
1 files changed, 30 insertions, 11 deletions
diff --git a/main.py b/main.py
index 4fdb82b..771059f 100644
--- a/main.py
+++ b/main.py
@@ -1,13 +1,32 @@
+import os
from datetime import datetime
from downloader import downloadCsv
from csvReader import readCSV
from bot import Bot
from schedule import every, repeat, run_pending
+from util import dbFile, initDb
import time
from util import setupLogger
logger = setupLogger()
+bot = Bot()
+
+
+def getScore():
+ downloadCsv()
+ myScore = readCSV()
+ try:
+ myScore = 100 * float(myScore)
+ except ValueError:
+ myScore = 0
+ return myScore
+
+
+def processMessages(messages):
+ if 'update' in messages:
+ score = getScore()
+ bot.sendMessage(f"Score leantime bulan ini = {score}%")
@repeat(every().day.at("09:00"))
@@ -16,24 +35,24 @@ def main():
today = datetime.today()
weekday = today.weekday()
if weekday not in [5, 6]: # jangan ganggu aku di akhir pekan
- downloadCsv()
- myScore = readCSV()
- try:
- myScore = 100 * float(myScore)
- except ValueError:
- myScore = 0
- bot = Bot()
- msg = f'Isi leantime... score ente bulan ini {myScore}%'
+ myScore = getScore()
+ msg = f"Leantime score = {myScore}%. <i>Jangan lupa isi leantime</i>"
if (17 <= today.day <= 24) and myScore < 70: # seminggu sebelumnya udah ngingetin
- msg = f'*WARNING!* SEKARANG UDAH TANGGAL {today.day}, SCORE LEANTIME MASIH {myScore}%'
+ msg = f'<b>WARNING!</b> SEKARANG UDAH TANGGAL {today.day}, SCORE LEANTIME MASIH {myScore}%'
- bot.send_message(msg)
+ bot.sendMessage(msg)
if __name__ == '__main__':
try:
+ if not os.path.isfile(dbFile):
+ initDb()
while True:
+ if not bot.isProcessingPolling and bot.hasNewMessages:
+ processMessages(bot.getNewMessages())
+ else:
+ bot.pollUpdate()
run_pending()
- time.sleep(3600)
+ time.sleep(1)
except BaseException as e:
logger.error(repr(e))