summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2024-07-27 14:05:23 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2024-07-27 14:05:23 +0700
commit65ffb05c0a9e7340b7139bb8363bdf83a1a0facd (patch)
tree63099550cd44a91bb37385aa369d94ec61437724
parent8c9f6940fcdfb0cb9d95bc24aff2e828067d9b3e (diff)
upd scheduler
-rw-r--r--bot.py4
-rw-r--r--main.py32
-rw-r--r--requirements.txt1
3 files changed, 26 insertions, 11 deletions
diff --git a/bot.py b/bot.py
index c86c55b..99485dc 100644
--- a/bot.py
+++ b/bot.py
@@ -20,7 +20,7 @@ class Bot:
def send_message(self, message):
message = parse.quote_plus(message)
- url = f'https://api.telegram.org/bot{self.token}/sendMessage?chat_id={self.chatId}&text={message}'
+ url = f'https://api.telegram.org/bot{self.token}/sendMessage?chat_id={self.chatId}&parse_mode=MarkdownV2&text={message}'
response = requests.get(url)
if response.status_code == 200:
logger.info(f'Message sent: {response.text}')
@@ -30,4 +30,4 @@ class Bot:
if __name__ == '__main__':
bot = Bot()
- bot.send_message('ngetest aja bangsat')
+ bot.send_message('*harusnya ini bold* dan ini ngga')
diff --git a/main.py b/main.py
index 5ff4015..14cb816 100644
--- a/main.py
+++ b/main.py
@@ -1,18 +1,32 @@
+from datetime import datetime
+
from downloader import downloadCsv
from csvReader import readCSV
from bot import Bot
+from schedule import every, repeat, run_pending
+import time
+@repeat(every().day.at("09:00"))
def main():
- downloadCsv()
- myScore = readCSV()
- try:
- myScore = 100 * float(myScore)
- except ValueError:
- myScore = 0
- bot = Bot()
- bot.send_message(f'Score leantime ente bulan ini {myScore}%')
+ 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}%'
+ if (17 <= today.day <= 24) and myScore < 70: # seminggu sebelumnya udah ngingetin
+ msg = f'*WARNING!!* SEKARANG UDAH TANGGAL {today.day}, SCORE LEANTIME MASIH {myScore}%'
+
+ bot.send_message(msg)
if __name__ == '__main__':
- main()
+ while True:
+ run_pending()
+ time.sleep(3600)
diff --git a/requirements.txt b/requirements.txt
index cf2b4d7..067dc1e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,6 +9,7 @@ PySocks==1.7.1
python-dotenv==1.0.1
PyVirtualDisplay==3.0
requests==2.32.3
+schedule==1.2.2
selenium==4.23.1
sniffio==1.3.1
sortedcontainers==2.4.0