Home - socialatm/draftkings GitHub Wiki

DraftKings Odds Scraper

This code is a web scraping program that automatically monitors UFC (Ultimate Fighting Championship) betting odds from the DraftKings sportsbook website. Think of it as a digital assistant that continuously watches for new UFC fights and their betting odds, then alerts you whenever new fights are announced.

Purpose of the Code

The main purpose is to track UFC fight odds in real-time and notify users when new fights become available for betting. Instead of manually checking the DraftKings website repeatedly, this program does it automatically and saves all the information to a file while sending email notifications about new fights.

Input and Output

The program doesn't require any direct input from the user when it runs. Instead, it takes its input by fetching data from the DraftKings UFC odds webpage. The outputs include: a CSV file named 'UFC_fight_odds.csv' that stores all fight data, email notifications sent when new fights are discovered, and console messages showing the program's status and any errors.

How It Achieves Its Purpose

The program works through a continuous monitoring system. It starts by loading any previously saved fight data from a CSV file. Then it visits the DraftKings website and downloads the webpage content, which contains HTML code with fight information embedded in it. The program uses a tool called BeautifulSoup to parse through this HTML and extract specific pieces of information: fighter names, their betting odds, and unique fight identifiers.

Logic Flow and Data Processing

The core logic follows a cycle that repeats every 60 seconds. First, the program scrapes the website and organizes the raw data into a structured format with columns for each fighter's name, odds, and bout ID. It then compares this new data against previously stored data to identify any new fights that weren't there before. When new fights are found, the program creates a formatted message containing the fight details and sends an email notification. Finally, it saves the new fight information to the CSV file and waits 60 seconds before starting the cycle again.

The program includes error handling to deal with network issues or website problems. If the website doesn't respond properly, it will retry up to 5 times with delays between attempts. This makes the program more reliable and less likely to crash due to temporary internet or website issues.