Skip to content

Commit

Permalink
Update moodle_alert_system.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfaaqrifath authored Jan 13, 2024
1 parent 4d15333 commit ff56fa1
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions moodle_alert_system.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import requests
from bs4 import BeautifulSoup

def get_div_class(url):
response = requests.get(url)
bs = BeautifulSoup(response.text, "html.parser")
element = bs.find_all('div', class_="post-content-container")[:3]
notice_list = []

for notice in element:
notice_list.append(notice.text)
return notice_list

def get_content(url):
def get_h3_class(url):
response = requests.get(url)
bs = BeautifulSoup(response.text, "html.parser")
element = bs.find_all("article")[:3]
element = bs.find_all('h3', class_="h6 font-weight-bold mb-0")[:3]
title_list = []

for title in element:
title_list.append(title.text)
return title_list

def get_time_element(url):
response = requests.get(url)
bs = BeautifulSoup(response.text, "html.parser")
element = bs.find_all("time")[:3]
time_list = []

for time in element:
time_list.append(time.text)
return time_list

article_list = []

for article in element:
article_list.append(article.text)
return article_list

def telegram_notification(send):
bot_token = "6585671034:AAEemxbzcNCaPv-xrKK1Ro3eedvqbV20gHc"
my_chatID = "1813981055"
Expand All @@ -23,23 +42,31 @@ def telegram_notification(send):


site_url = "https://sam.sliitacademy.lk/"
content = get_content(site_url)

if content != None:
i = 0
for item in content:
i = i + 1
notice = str(item)
content = get_div_class(site_url)
title = get_h3_class(site_url)
time = get_time_element(site_url)

if content is not None and title is not None and time is not None:
num = 0
for i in range(3):
num = num + 1
notice_content = str(content[i])
notice_title = str(title[i])
notice_time = str(time[i])

output = f'''
SITE ANNOUNCEMENTS - SLIITA
NOTICE {i} 🔴
{notice}
*SITE ANNOUNCEMENT {num} 🔴*
*{notice_title}*
_{notice_time}_
{notice_content}
{'='*30}
Moodle Alert System - v1.0.0
Copyright (c) Ashfaaq Rifath'''
_SLIIT Moodle Alert System - v1.2.0_
_Copyright (c) Ashfaaq Rifath_'''

print(output)
telegram_notification(output)
else:
print("error")
print("error")

0 comments on commit ff56fa1

Please sign in to comment.