Skip to content

Commit

Permalink
Update and rename moodle_alert_system.py to moodle_alert_system.pyw
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfaaqrifath authored Mar 8, 2024
1 parent 63c9e27 commit 5cf44fe
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions moodle_alert_system.py → moodle_alert_system.pyw
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import os
import time
import telebot
import requests
import threading
import subprocess
import importlib

packages = ["telebot", "requests", "beautifulsoup4", "plyer"]

for pkg in packages:
if importlib.util.find_spec(pkg) is None:
subprocess.check_call(["pip", "install", pkg])
else:
pass

import telebot
import requests
from bs4 import BeautifulSoup
from plyer import notification


def get_div_class(url):
response = requests.get(url)
bs = BeautifulSoup(response.text, "html.parser")
Expand Down Expand Up @@ -38,7 +49,7 @@ def get_time_element(url):
return time_list

def telegram_alert(send):
bot_token = "YOUR BOT TOKEN"
bot_token = "BOT TOKEN"
my_chatID = "CHAT ID"
send_text = "https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + my_chatID + "&parse_mode=Markdown&text=" + send

Expand All @@ -62,7 +73,7 @@ def telegram_alert(send):

###########################################################################

bot = telebot.TeleBot("YOUR BOT TOKEN")
bot = telebot.TeleBot("BOT TOKEN")
@bot.message_handler(func=lambda message: True)

def command_engine(message):
Expand All @@ -74,9 +85,9 @@ def command_engine(message):
time_stamp = get_time_element(site_url)

if content is not None and title is not None and time_stamp is not None:
num = 0
for i in range(3):
num = num + 1
num = 4
for i in range(2, -1, -1):
num = num - 1
notice_content = str(content[i])
notice_title = str(title[i])
notice_time = str(time_stamp[i])
Expand All @@ -89,7 +100,7 @@ def command_engine(message):
{notice_content}
{'-'*50}
_SLIIT Moodle Alert System - v1.4_
_SLIIT Moodle Alert System - v1.5_
_Copyright (c) Ashfaaq Rifath_'''

telegram_alert(output)
Expand All @@ -109,15 +120,15 @@ def command_engine(message):
bot.reply_to(message, "Invalid Command")

def telegram_bot():
for x in range(1000):
while True:
try:
bot.polling()
except:
#print("bot")
time.sleep(5)

def moodle_alert_system():
for x in range(1000):
while True:
try:
site_url = "https://sam.sliitacademy.lk/"

Expand All @@ -126,9 +137,9 @@ def moodle_alert_system():
time_stamp = get_time_element(site_url)

if content is not None and title is not None and time_stamp is not None:
num = 0
for i in range(3):
num = num + 1
num = 4
for i in range(2, -1, -1):
num = num - 1
notice_content = str(content[i])
notice_title = str(title[i])
notice_time = str(time_stamp[i])
Expand All @@ -142,7 +153,7 @@ def moodle_alert_system():
{notice_content}
{'-'*50}
_SLIIT Moodle Alert System - v1.4_
_SLIIT Moodle Alert System - v1.5_
_Copyright (c) Ashfaaq Rifath_'''

telegram_alert(output)
Expand Down

0 comments on commit 5cf44fe

Please sign in to comment.