Skip to content

edavis0/college-football-betting-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

College-Football-Betting-Python

Overview

This repository contains source code allowing the user to simulate betting on American college football games. It utilizes the CFBD Python API. For more information regarding the CFBD APIs and databases, please refer to this link. This program offers the same functionality provided by the College-Football-Betting-Javascript repository.

The following sections detail the process flow of the program and its relevant functions.

Installation

You can simply clone this reposity and run the script by accessing the app directory and running python3 main.py, assuming you have a CFBD API key, created a .env file with a api-token=<API-KEY> entry, and install the packages in your virtual environment, as detailed in requirements.txt.

Using a Virtual Environment with venv

Here are the steps for creating a virtual environment and running this project in it.

  1. Open a terminal window and navigate to the project directory, once you have cloned it to your machine.
  2. Create a new virtual environment using the following command: python3 -m venv myenv. This will create a new directory named myenv in your project directory, containing the virtual environment.
  3. Activate the virtual environment: source myenv/bin/activate. This will activate the virtual environment, which will modify your shell's environment variables to use the Python interpreter and packages installed in the virtual environment.
  4. Install the required packages using the requirements.txt file: pip3 install -r requirements.txt. This will install all the required packages listed in the requirements.txt file.
  5. Run the project: python3 main.py. This will run the project using the Python interpreter installed in the virtual environment. To exit the virtual environment, simply run the deactivate command: deactivate.

Bet Types

Two bet types are used in this program: point spread bets and total point bets (also known as over/under bets). For more information regarding the mechanics of these bets, refer to this link.

CatchAllFunctions.py

GetHomeVsVisitorScore(api_instance, year, week, team, conference)

Returns the current game score as a string in the following form: {home team name} {home team score} - {away team name} {away team score} Example:

Florida 29 - Alabama 31

PrintFunctions.py

PrintAllGamesBettingData(api_instance, year, week, conference)

Prints betting information for every game in the user's chosen conference and week. This is printed to console in table form using the Tabulate Python library. Example:

+-----------+-----------+--------------+--------+------------+
| Home Team | Away Team | Bet Provider | Spread | Over/Under |
+-----------+-----------+--------------+--------+------------+
+---------+---------+--------+---------------+------+
| Florida | Alabama | Bovada | Alabama -14.5 | 60.5 |
+---------+---------+--------+---------------+------+

PrintSingleGameBettingData(api_instance, year, week, team, conference)

Prints betting information for a single game using the user's chosen year, week, team, and conference. This isn't used in the current iteration of main.py.
Example:

Bet Provider	Spread		Over Under
------------------------------------------
consensus:	Alabama -14	60
numberfire:	Alabama -15.5	58.5
teamrankings:	Alabama -14	59.5
Bovada:	Alabama -14.5	60.5
William Hill (New Jersey):	Alabama -14	60

SpreadFunctions.py

GetFavoredAndUnfavoredTeamList(betProvider, api_instance, year, week, team, conference)

Returns a list of the favored and unfavored teams from the chosen bet. The list's format is as follows:
[favored team name string, unfavored team name string].
Example:

listFavoredAndUnfavoredTeams = [favoredTeam, unfavoredTeam]
favoredTeam = 'Alabama'
unfavoredTeam = 'Florida'

GetUserBetOnFavoredOrUnfavoredTeam(favoredTeam, team)

Returns a boolean identifying if the user chose the favored team or not. If the user is betting on the favored team, the return boolean betOnFavoredTeam will be set to True. If the user is betting on the unfavored team, the return boolean betOnFavoredTeam will be set to False.

GetUserSpreadLine(betProvider, api_instance, year, week, team, conference, listFavoredAndUnfavoredTeams, betOnFavoredTeam)

Returns the line of the chosen point spread as a floating point number.
Example:

chosenSpread = -14.5

PrintSpreadBettingInfo(betSpreadOrLine, listFavoredAndUnfavoredTeams, chosenTeam)

Prints the user's chosen point spread betting information.
Example:

The chosen spread is -14.5
The chosen team is Alabama
Favored team: Alabama
Unfavored team: Florida

GetScoreDifferentialList(api_instance, year, week, team, conference, favoredTeam)

Returns a list of the the game score differential information. The list's format is as follows: [score differential integer, formatted score differential string, favored team score integer, unfavored team score integer]
Example:

listScoreInfo = [int(scoreDiff), formattedScoreDiff, int(favoredTeamScore), int(unfavoredTeamScore)]
scoreDiff = -2
formattedScoreDiff = 'Alabama is winning by 2 points'
favoredTeamScore = 31
unfavoredTeamScore = 29

PrintSpreadBetCurrentScoreInfo(homeVsVistorScore,listScoreDifferential)

Prints the current score information.
Example:

Current Score: Florida 29 - Alabama 31
Favored team score: 31
Unfavored team score: 29
Alabama is winning by 2 points

CalculateCashFromSpreadBet(currentCash, betAmount, betOnFavoredTeam, betSpread, scoreDiff)

Returns an integer of the user's new cash amount after the game is complete.
Example:

newCash = 2750

TotalFunctions.py

GetUserBetOnOverOrUnder(userInputOverOrUnder)

Returns a list of the user's point total bet information. The list's format is as follows: [user bet on over or under boolean, over or under string]. If the user bets on the over, the boolBetOnOver will be set to True. If the user bets on the under, he boolBetOnOver will be set to False. Example:

listUserOverOrUnder = [boolBetOnOver, stringOverOrUnder]
boolBetOnOver = True
stringOverOrUnder = 'over'

GetUserTotalLine(betProvider, api_instance, year, week, team, conference)

Returns the line of the user's point total bet as a floating point number. Example:

betLine = 60.5

GetTotalScore(api_instance, year, week, team, conference)

Returns the total score score of the game as an integer. For example, if Florida scores 29 points and Alabama scores 31 points, the total score will be equal to 60 points. Example:

totalScore = 60

PrintTotalBetCurrentScoreInfo(homeVsVistorScore,totalScore)

Prints the current or final score of the user's chosen total point bet. Example:

Current Score: Florida 29 - Alabama 31
Total Score: 60

CalculateCashFromTotalBet(currentCash, betAmount, betLine, betOnOver, actualTotalScore)

Calculates the user's current cash based on the outcome of the point total bet.

api_instance.get_lines Response Example

When the CFBD .get_lines method is executed, the following output is generated. The data type is a list.

[{'away_conference': 'SEC',
'away_score': 47,
'away_team': 'Alabama',
'home_conference': 'SEC',
'home_score': 23,
'home_team': 'South Carolina',
'id': 401110794,
'lines': [{'formattedSpread': 'Alabama -26.5',
            'overUnder': '59.5',
            'overUnderOpen': None,
            'provider': 'consensus',
            'spread': '26.5',
            'spreadOpen': None},
        {'formattedSpread': 'Alabama -26.5',
            'overUnder': '59',
            'overUnderOpen': None,
            'provider': 'Caesars',
            'spread': '26.5',
            'spreadOpen': None},
        {'formattedSpread': 'Alabama -26',
            'overUnder': '60',
            'overUnderOpen': None,
            'provider': 'numberfire',
            'spread': '26',
            'spreadOpen': None},
        {'formattedSpread': 'Alabama -25.5',
            'overUnder': '59.5',
            'overUnderOpen': None,
            'provider': 'teamrankings',
            'spread': '25.5',
            'spreadOpen': None}],
'season': 2019,
'season_type': 'regular',
'week': 3}]

Imagery from Flaticon.com

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages