import schedule import time import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from datetime import datetime import asyncio from playwright.async_api import async_playwright import requests from bs4 import BeautifulSoup import urllib3 import re # Disable SSL warnings urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Email configuration EMAIL_CONFIG = { 'smtp_server': 'smtp.gmail.com', # Change this for your email provider 'smtp_port': 587, 'sender_email': 'mblanke@gmail.com', # Replace with your email 'sender_password': 'vyapvyjjfrqpqnax', # App password (spaces removed) 'recipient_email': 'mblanke@gmail.com', # Replace with recipient email } # Common headers to mimic a browser request HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.9", } # Scraping functions def get_powerball(): """Get Powerball jackpot from lotto.net""" try: url = "https://www.lotto.net/powerball" response = requests.get(url, timeout=10, verify=False, headers=HEADERS) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') # Look for "Next Jackpot" text all_text = soup.get_text() lines = all_text.split('\n') for i, line in enumerate(lines): if 'Next Jackpot' in line and i + 1 < len(lines): next_line = lines[i + 1].strip() if '$' in next_line and 'Million' in next_line: # Parse the amount match = re.search(r'\$\s*([\d,]+(?:\.\d+)?)\s*Million', next_line) if match: amount_str = match.group(1).replace(',', '') return float(amount_str) except Exception as e: print(f"Error getting Powerball: {e}") return None def get_mega_millions(): """Get Mega Millions jackpot from lotto.net""" try: url = "https://www.lotto.net/mega-millions" response = requests.get(url, timeout=10, verify=False, headers=HEADERS) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') # Look for "Next Jackpot" text all_text = soup.get_text() lines = all_text.split('\n') for i, line in enumerate(lines): if 'Next Jackpot' in line and i + 1 < len(lines): next_line = lines[i + 1].strip() if '$' in next_line and 'Million' in next_line: # Parse the amount match = re.search(r'\$\s*([\d,]+(?:\.\d+)?)\s*Million', next_line) if match: amount_str = match.group(1).replace(',', '') return float(amount_str) except Exception as e: print(f"Error getting Mega Millions: {e}") return None async def get_canadian_lotteries(): """Get Lotto Max and Lotto 6/49 jackpots using Playwright""" lotto_max = None lotto_649 = None try: async with async_playwright() as p: browser = await p.chromium.launch(headless=True) page = await browser.new_page() await page.goto('https://www.olg.ca/', wait_until='networkidle') await page.wait_for_timeout(2000) content = await page.content() # Lotto Max pattern lotto_max_pattern = r'LOTTO\s*MAX(?:(?!LOTTO\s*6/49).)*?\$\s*([\d.,]+)\s*Million' match = re.search(lotto_max_pattern, content, re.IGNORECASE | re.DOTALL) if match: amount_str = match.group(1).replace(',', '') lotto_max = float(amount_str) # Lotto 6/49 pattern lotto_649_pattern = r'LOTTO\s*6/49.*?\$\s*([\d.,]+)\s*Million' match = re.search(lotto_649_pattern, content, re.IGNORECASE | re.DOTALL) if match: amount_str = match.group(1).replace(',', '') lotto_649 = float(amount_str) await browser.close() except Exception as e: print(f"Error getting Canadian lotteries: {e}") return lotto_max, lotto_649 def format_currency(amount): """Format amount as currency""" if amount is None: return "Not available" return f"${amount:,.0f}M" def create_email_html(powerball, mega_millions, lotto_max, lotto_649): """Create HTML email content""" html = f"""