import requests
import schedule
import time
import smtplib
from email.mime.text import MIMEText
# List of websites to track
websites = {
"Google": "https://www.google.com",
"My Portfolio": "https://yourportfolio.com"
}
# Email Config
EMAIL_ADDRESS = "your_email@gmail.com"
EMAIL_PASSWORD = "your_app_password"
TO_EMAIL = "recipient_email@example.com"
def send_email_alert(site):
msg = MIMEText(f"Alert: {site} is DOWN!")
msg["Subject"] = f"🚨 {site} is Down!"
msg["From"] = EMAIL_ADDRESS
msg["To"] = TO_EMAIL
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
print(f"Email sent: {site} is down.")
def check_sites():
for name, url in websites.items():
try:
response = requests.get(url, timeout=5)
if response.status_code != 200:
print(f"[{name}] Status: {response.status_code}")
send_email_alert(name)
else:
print(f"[{name}] is up ✅")
except requests.exceptions.RequestException:
print(f"[{name}] is unreachable ❌")
send_email_alert(name)
# Check every 5 minutes
schedule.every(5).minutes.do(check_sites)
print("🔍 Website Uptime Tracker Started...")
while True:
schedule.run_pending()
time.sleep(1)
Twilio SMS Integration
No comments:
Post a Comment