|
| 1 | +import time |
| 2 | +import smtplib |
| 3 | +from plyer import notification |
| 4 | +from twilio.rest import Client |
| 5 | +import requests |
| 6 | + |
| 7 | +NOTIFICATION_METHODS = { |
| 8 | + 'desktop': True, |
| 9 | + 'email': True, |
| 10 | + 'sms': True |
| 11 | +} |
| 12 | +EMAIL_ADDRESS = ' [email protected]' |
| 13 | +EMAIL_PASSWORD = 'your_email_password' |
| 14 | + |
| 15 | +TWILIO_SID = 'your_twilio_sid' |
| 16 | +TWILIO_AUTH_TOKEN = 'your_twilio_auth_token' |
| 17 | +TWILIO_PHONE_NUMBER = 'your_twilio_phone_number' |
| 18 | +TO_PHONE_NUMBER = 'recipient_phone_number' |
| 19 | + |
| 20 | +def check_competitions(): |
| 21 | + # Replace with your actual logic to fetch competitions |
| 22 | + competitions = [ |
| 23 | + {"name": "Codeforces Round", "date": "2024-10-28", "url": "https://codeforces.com"}, |
| 24 | + {"name": "AtCoder Beginner Contest", "date": "2024-10-29", "url": "https://atcoder.jp"}, |
| 25 | + ] |
| 26 | + return competitions |
| 27 | +def notify_desktop(competition): |
| 28 | + notification.notify( |
| 29 | + title=f"Upcoming Competition: {competition['name']}", |
| 30 | + message=f"Date: {competition['date']}\nURL: {competition['url']}", |
| 31 | + app_name='CP Notifier', |
| 32 | + timeout=10 |
| 33 | + ) |
| 34 | +def notify_email(competition): |
| 35 | + with smtplib.SMTP('smtp.gmail.com', 587) as server: |
| 36 | + server.starttls() |
| 37 | + server.login(EMAIL_ADDRESS, EMAIL_PASSWORD) |
| 38 | + subject = f"Upcoming Competition: {competition['name']}" |
| 39 | + body = f"Date: {competition['date']}\nURL: {competition['url']}" |
| 40 | + message = f'Subject: {subject}\n\n{body}' |
| 41 | + server.sendmail(EMAIL_ADDRESS, TO_EMAIL, message) |
| 42 | + |
| 43 | +def notify_sms(competition): |
| 44 | + client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN) |
| 45 | + message = client.messages.create( |
| 46 | + body=f"Upcoming Competition: {competition['name']}\nDate: {competition['date']}\nURL: {competition['url']}", |
| 47 | + from_=TWILIO_PHONE_NUMBER, |
| 48 | + to=TO_PHONE_NUMBER |
| 49 | + ) |
| 50 | +def run_notifier(): |
| 51 | + while True: |
| 52 | + competitions = check_competitions() |
| 53 | + for competition in competitions: |
| 54 | + if NOTIFICATION_METHODS['desktop']: |
| 55 | + notify_desktop(competition) |
| 56 | + if NOTIFICATION_METHODS['email']: |
| 57 | + notify_email(competition) |
| 58 | + if NOTIFICATION_METHODS['sms']: |
| 59 | + notify_sms(competition) |
| 60 | + time.sleep(86400) |
| 61 | + |
| 62 | +if __name__ == "__main__": |
| 63 | + run_notifier() |
0 commit comments