Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CP Notifier Script #1006

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions CP Notifier Script
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import time
import smtplib
from plyer import notification
from twilio.rest import Client
import requests

NOTIFICATION_METHODS = {
'desktop': True,
'email': True,
'sms': True
}
EMAIL_ADDRESS = '[email protected]'
EMAIL_PASSWORD = 'your_email_password'
TO_EMAIL = '[email protected]'
TWILIO_SID = 'your_twilio_sid'
TWILIO_AUTH_TOKEN = 'your_twilio_auth_token'
TWILIO_PHONE_NUMBER = 'your_twilio_phone_number'
TO_PHONE_NUMBER = 'recipient_phone_number'

def check_competitions():
# Replace with your actual logic to fetch competitions
competitions = [
{"name": "Codeforces Round", "date": "2024-10-28", "url": "https://codeforces.com"},
{"name": "AtCoder Beginner Contest", "date": "2024-10-29", "url": "https://atcoder.jp"},
]
return competitions
def notify_desktop(competition):
notification.notify(
title=f"Upcoming Competition: {competition['name']}",
message=f"Date: {competition['date']}\nURL: {competition['url']}",
app_name='CP Notifier',
timeout=10
)
def notify_email(competition):
with smtplib.SMTP('smtp.gmail.com', 587) as server:
server.starttls()
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
subject = f"Upcoming Competition: {competition['name']}"
body = f"Date: {competition['date']}\nURL: {competition['url']}"
message = f'Subject: {subject}\n\n{body}'
server.sendmail(EMAIL_ADDRESS, TO_EMAIL, message)

def notify_sms(competition):
client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)
message = client.messages.create(
body=f"Upcoming Competition: {competition['name']}\nDate: {competition['date']}\nURL: {competition['url']}",
from_=TWILIO_PHONE_NUMBER,
to=TO_PHONE_NUMBER
)
def run_notifier():
while True:
competitions = check_competitions()
for competition in competitions:
if NOTIFICATION_METHODS['desktop']:
notify_desktop(competition)
if NOTIFICATION_METHODS['email']:
notify_email(competition)
if NOTIFICATION_METHODS['sms']:
notify_sms(competition)
time.sleep(86400)

if __name__ == "__main__":
run_notifier()