charaka scraper
unknown
python
2 years ago
1.8 kB
3
Indexable
Never
import requests import telepot from bs4 import BeautifulSoup login_url = 'https://charaka.wbuhs.ac.in/home/authenticate' result_url = 'https://charaka.wbuhs.ac.in/ExamEnrollment/GetMarksStatementDetails?ScheduleID=669' telegram_token = '5334780815:AAHvvq9c26PIlumiMtzmkYp7R2B3FKkFQKw' telegram_receiver_id = 614975195 payload = { 'UserName': '', 'Password': '', 'LoginType': '3' } def get_message(marks, grade, total): total = int(total) if total >= 50: message = f'Congrats Butu! You have passed ❤ :) Pedia Marks⬆📈' + f'\n\nNew marks: {marks}, Total: {total}, Grade: {grade}' + '\n\nYipee! My butu is now a doctor 👩⚕️' elif total == 46: message = f'Marks still same...... 😪' + f'\n\nMarks: {marks}, Total:{total}, Grade: {grade}\n\nPlease wait for the next update ⏱' else: message = f'Marks: {marks}, Total: {total}, Grade: {grade}' return message def send_telegram_message(message): bot = telepot.Bot(telegram_token) bot.sendMessage(telegram_receiver_id, message) with requests.session() as s: s.post(login_url, data=payload) r = s.get(result_url) soup = BeautifulSoup(r.content, 'html.parser') tds = soup.find_all("td", text="Paediatrics (including Neonatology)") # .find_next_sibling("td") for i, td in enumerate(tds): td1 = td.find_next_sibling("td") td2 = td1.find_next_sibling("td") td3 = td2.find_next_sibling("td") td4 = td3.find_next_sibling("td") if i == 2: pedia_marks = td4.text if i == 8: pedia_grade = td4.text pedia_total = td3.text message = get_message(pedia_marks, pedia_grade, pedia_total) send_telegram_message(message)