An AI project that includes a scraper for NFL data, postgres database, and user interface. It uses a classification algorithm to predict winners.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | """ |
| 14 | ## Manages access to the internal nfl.com api |
| 15 | |
| 16 | ### Global Variables |
| 17 | * `BMP_PATH` - Path to browsermob-proxy |
| 18 | * `AUTH_PATH` - Path to auth file |
| 19 | * `AUTH_ENDPOINT` - Endpoint used to get auth token |
| 20 | * `API_ROOT` - Root for nfl.com api endpoints |
| 21 | * `HAR_DIR` - Storage directory for har files |
| 22 | * `URL_JSON_PATH` - Path for json list of found api endpoints |
| 23 | * `OPENAPI_PATH` - Path for openapi yaml |
| 24 | * `TOKEN_EXPIRE_RATE` - How many seconds to download a new auth token |
| 25 | * `TOKEN_AUTH_TIMEOUT` - Timeout when searching har file for Authorization |
| 26 | |
| 27 | ### Class Variables |
| 28 | * `har` - The current har in json |
| 29 | * `har_path` - Where to store the current har |
| 30 | * `server` - The browsermob server |
| 31 | * `proxy` - The browsermob proxy |
| 32 | * `driver` - The selenium driver |
| 33 | * `auth_token` - The current auth token |
| 34 | * `last_auth_download_time` - When the current auth token was downloaded |
| 35 | * `headers` - Headers sent through requests |
| 36 | |
| 37 | ### Notes |
| 38 | * HAR stands for HTTP Access Requests. This is like the network tab on Chrome inspector. |
| 39 | """ |
| 40 | = |
| 41 | = |
| 42 | = |
| 43 | = |
| 44 | = |
| 45 | = |
| 46 | = |
| 47 | = 60*60 |
| 48 | = 10 |
| 49 | |
| 50 | # Har download variables |
| 51 | = |
| 52 | = None |
| 53 | = None |
| 54 | = None |
| 55 | = None |
| 56 | |
| 57 | # Auth variables |
| 58 | = None |
| 59 | = 0 |
| 60 | = |
| 61 | |
| 62 | |
| 63 | |
| 64 | = |
| 65 | |
| 66 | |
| 67 | """Loads the auth token into the client.""" |
| 68 | |
| 69 | |
| 70 | = |
| 71 | = |
| 72 | = |
| 73 | |
| 74 | |
| 75 | = |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | """Prepares the driver and proxy to get the har""" |
| 81 | = or |
| 82 | # Start BrowserMob Proxy |
| 83 | = |
| 84 | |
| 85 | = |
| 86 | |
| 87 | # Configure Chrome with the proxy |
| 88 | = |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | = |
| 94 | # Navigate to the website |
| 95 | |
| 96 | |
| 97 | # Start capturing network traffic |
| 98 | |
| 99 | |
| 100 | # Create the path for storing har data |
| 101 | |
| 102 | = |
| 103 | = |
| 104 | = |
| 105 | |
| 106 | = |
| 107 | = / |
| 108 | |
| 109 | |
| 110 | """Closes the driver and proxy""" |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | """Downloads the auth token using the scores page of nfl.com""" |
| 116 | = |
| 117 | |
| 118 | # Capture the HAR once |
| 119 | = |
| 120 | |
| 121 | = |
| 122 | |
| 123 | |
| 124 | = |
| 125 | return |
| 126 | |
| 127 | return None |
| 128 | |
| 129 | |
| 130 | """Stores the current auth token""" |
| 131 | # Store the auth token |
| 132 | = |
| 133 | = |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | """Stores the current har""" |
| 142 | # Store the har data |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | """Downloads the auth token""" |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | """Downloads the endpoints found in har, stores json, updates readme, updates Mixin for the class""" |
| 156 | |
| 157 | = |
| 158 | |
| 159 | |
| 160 | = |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | # Load previous urls |
| 167 | = |
| 168 | |
| 169 | |
| 170 | = |
| 171 | |
| 172 | # Gather the list of endpoints |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | # Store the url json |
| 178 | |
| 179 | |
| 180 | |
| 181 | # Store the url openapi |
| 182 | |
| 183 | |
| 184 | |
| 185 | return |
| 186 | |
| 187 | |
| 188 | """Request an endpoint""" |
| 189 | |
| 190 | = |
| 191 | |
| 192 | return |
| 193 | |
| 194 | |
| 195 | """## Get summary of games during a week. |
| 196 | ### Args |
| 197 | * `season`: Year of the season (i.e. 2023) |
| 198 | * `week`: Week of the season (i.e. 3) |
| 199 | * `seasonType`: `REG` or `PRE` |
| 200 | * `withExternalIds`: boolean |
| 201 | """ |
| 202 | = f |
| 203 | return |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | """## Get game details. |
| 209 | ### Args |
| 210 | * `game_id`: Can be found iterating the week. |
| 211 | * `withExternalIds`: boolean |
| 212 | """ |
| 213 | return |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | """## Get team standings. |
| 219 | ### Args |
| 220 | * `season`: Year of the standings (i.e. 2023) |
| 221 | * `week`: Week of the standings (i.e. 3) |
| 222 | * `seasonType`: `REG` or `PRE` |
| 223 | * `limit`: Max items to get |
| 224 | """ |
| 225 | return |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | """## Get game results. |
| 234 | ### Args |
| 235 | * `game_summary_id`: Lookup id, can be found in `get_week`. |
| 236 | """ |
| 237 | return |
| 238 | |
| 239 | |
| 240 | """## Get game summaries for a week. |
| 241 | ## Args |
| 242 | * `season`: Season |
| 243 | * `week`: Week |
| 244 | * `seasonType`: `REG` or `PRE` |
| 245 | """ |
| 246 | return |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | """## Get teams in season. |
| 254 | ### Args |
| 255 | * `season`: Year |
| 256 | * `limit`: Query limit |
| 257 | """ |
| 258 | return |
| 259 | |
| 260 | |
| 261 |