summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/main.py b/main.py
index 655fbeb..17d7bbc 100644
--- a/main.py
+++ b/main.py
@@ -4,7 +4,7 @@ from downloader import downloadCsv
from csvReader import readCSV
from bot import Bot
from schedule import every, repeat, run_pending
-from util import dbFile, initDb
+from util import dbFile, initDb, getDbConn
import time
from util import setupLogger
@@ -51,13 +51,37 @@ def processMessages(messages):
if msg == 'update':
logger.info("EXPLICIT SCORE UPDATE REQUESTED")
score = getScore()
- msg = f"Score leantime bulan ini = {score}%" if score >= 0 else "Koneksi ke dashboard bermasalah"
- bot.sendMessage(msg)
- elif 'log' in msg:
+ msgSend = f"Score leantime bulan ini = {score}%" if score >= 0 else "Koneksi ke dashboard bermasalah"
+ bot.sendMessage(msgSend)
+ elif 'getlog' in msg:
sendLog(msg)
- elif msg == 'clean':
+ elif msg == 'cleanlog':
open(os.getenv('LOGFILE'), 'w').close()
bot.sendMessage("Log dihapus", log=False)
+ elif msg == 'cleandb':
+ connn = getDbConn()
+ cur = connn.cursor()
+ cur.execute("DELETE FROM incoming")
+ """
+ getUpdate di server telegram harus dibersihin juga, kalo ngga bakal ngeloop terus2an
+ db bersih -> ngirim konfirmasi ke gw -> polling dapet data baru -> ditandai belum dibaca
+ -> ngeliat ada command cleandb di antrian -> cleandb -> ngirim konfirmasi -> polling dst
+ """
+ bot.cleanTelegramApiQueue()
+ connn.commit()
+ connn.close()
+ bot.sendMessage("DB dihapus")
+ logger.info("DB Cleaned")
+ elif msg == 'status':
+ fileStat = os.stat(os.getenv('LOGFILE'))
+ msgSend = f'Log file = {fileStat.st_size / 1024}kB'
+ connn = getDbConn()
+ cur = connn.cursor()
+ cur.execute("SELECT COUNT(*) FROM incoming")
+ res = cur.fetchone()
+ msgSend += f'\nDB = {res[0]} rows'
+ bot.sendMessage(msgSend)
+ connn.close()
@repeat(every().day.at("09:00"))