cfbd_json_py.drives

  1# Creation Date: 08/30/2023 01:13 EDT
  2# Last Updated Date: 08/28/2024 11:00 PM EDT
  3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com)
  4# File Name: drives.py
  5# Purpose: Houses functions pertaining to CFB drive data within the CFBD API.
  6###############################################################################
  7
  8import logging
  9from datetime import datetime
 10
 11import pandas as pd
 12import requests
 13
 14from cfbd_json_py.utls import get_cfbd_api_token
 15
 16
 17def get_cfbd_drives_info(
 18    api_key: str = None,
 19    api_key_dir: str = None,
 20    season: int = None,
 21    season_type: str = "regular",
 22    week: int = None,
 23    team: str = None,
 24    offensive_team: str = None,
 25    defensive_team: str = None,
 26    conference: str = None,
 27    offensive_conference: str = None,
 28    defensive_conference: str = None,
 29    ncaa_division: str = "fbs",
 30    year: int = None,
 31    offense: str = None,
 32    defense: str = None,
 33    classification: str = None,
 34    return_as_dict: bool = False,
 35):
 36    """
 37    Retrieves a list of CFB drives from the CFBD API.
 38
 39    Parameters
 40    ----------
 41    `season` (int, mandatory):
 42        Required argument.
 43        Specifies the season you want CFB drive information from.
 44        This must be specified, otherwise this package, and by extension
 45        the CFBD API, will not accept the request to get CFB drive information.
 46
 47    `api_key` (str, optional):
 48        Semi-optional argument.
 49        If `api_key` is null, this function will attempt to load a CFBD API key
 50        from the python environment, or from a file on this computer.
 51        If `api_key` is not null,
 52        this function will automatically assume that the
 53        inputted `api_key` is a valid CFBD API key.
 54
 55    `api_key_dir` (str, optional):
 56        Optional argument.
 57        If `api_key` is set to am empty string, this variable is ignored.
 58        If `api_key_dir` is null, and `api_key` is null,
 59        this function will try to find
 60        a CFBD API key file in this user's home directory.
 61        If `api_key_dir` is set to a string, and `api_key` is null,
 62        this function will assume that `api_key_dir` is a directory,
 63        and will try to find a CFBD API key file in that directory.
 64
 65    `season_type` (str, semi-optional):
 66        Semi-optional argument.
 67        By default, this will be set to "regular", for the CFB regular season.
 68        If you want CFB drive data for non-regular season games,
 69        set `season_type` to "postseason".
 70        If `season_type` is set to anything but "regular" or "postseason",
 71        a `ValueError()` will be raised.
 72
 73    `week` (int, optional):
 74        Optional argument.
 75        If `week` is set to an integer, this function will attempt
 76        to load CFB drive data from games in that season, and that week.
 77
 78    `team` (str, optional):
 79        Optional argument.
 80        If you only want CFB drive data for a team,
 81        regardless if they are the home/away team,
 82        set `team` to the name of the team you want CFB drive data from.
 83
 84    `offensive_team` (str, optional):
 85        Optional argument.
 86        If you only want CFB drive data from a team, while they are on offense,
 87        regardless if they are the home/away team,
 88        set `team` to the name of the team you want CFB drive data from.
 89
 90    `defensive_team` (str, optional):
 91        Optional argument.
 92        If you only want CFB drive data from a team, while they are on defense,
 93        regardless if they are the home/away team,
 94        set `team` to the name of the team you want CFB drive data from.
 95
 96    `conference` (str, optional):
 97        Optional argument.
 98        If you only want CFB drive data from games
 99        involving teams from a specific conference,
100        set `conference` to the abbreviation
101        of the conference you want CFB drive data from.
102        For a list of conferences,
103        use the `cfbd_json_py.conferences.get_cfbd_conference_info()`
104        function.
105
106    `offensive_conference` (str, optional):
107        Optional argument.
108        If you only want CFB drive data from games
109        where the offensive team is from a specific conference,
110        set `conference` to the abbreviation
111        of the conference you want CFB drive data from.
112        For a list of conferences,
113        use the `cfbd_json_py.conferences.get_cfbd_conference_info()`
114        function.
115
116    `defensive_conference` (str, optional):
117        Optional argument.
118        If you only want CFB drive data from games
119        where the defensive team is from a specific conference,
120        set `conference` to the abbreviation
121        of the conference you want CFB drive data from.
122        For a list of conferences,
123        use the `cfbd_json_py.conferences.get_cfbd_conference_info()`
124        function.
125
126    `ncaa_division` (str, semi-optional):
127        Semi-optional argument.
128        By default, `ncaa_division` will be set to "fbs",
129        short for the Football Bowl Subdivision (FBS),
130        formerly known as D1-A (read as "division one single A"),
131        the highest level in the NCAA football pyramid,
132        where teams can scholarship up to 85 players
133        on their football team solely for athletic ability,
134        and often have the largest athletics budgets
135        within the NCAA.
136
137        Other valid inputs are:
138        - "fcs": Football Championship Subdivision (FCS),
139            formerly known as D1-AA (read as "division one double A").
140            An FCS school is still in the 1st division of the NCAA,
141            making them eligible for the March Madness tournament,
142            but may not have the resources to compete at the FBS level
143            at this time. FCS schools are limited to 63 athletic scholarships
144            for football.
145        - "ii": NCAA Division II. Schools in this and D3 are not
146            eligible for the March Madness tournament,
147            and are limited to 36 athletic scholarships
148            for their football team.
149        - "iii": NCAA Division III. The largest single division within the
150            NCAA football pyramid.
151            D3 schools have the distinction of being part of
152            the only NCAA division that cannot give out scholarships solely
153            for athletic ability.
154
155    `offense` (str):
156        Alternative keyword for `offensive_team`
157
158    `defense` (str):
159        Alternative keyword for `defensive_team`
160
161    `classification` (str):
162        Alternative keyword for `ncaa_division`
163
164    `return_as_dict` (bool, semi-optional):
165        Semi-optional argument.
166        If you want this function to return the data
167        as a dictionary (read: JSON object),
168        instead of a pandas `DataFrame` object,
169        set `return_as_dict` to `True`.
170
171    Usage
172    ----------
173    ```
174    import time
175
176    from cfbd_json_py.drives import get_cfbd_drives_info
177
178    cfbd_key = "tigersAreAwesome"  # placeholder for your CFBD API Key.
179
180    if cfbd_key is not "tigersAreAwesome":
181        print(
182            "Using the user's API key declared in this script " +
183            "for this example."
184        )
185
186        # Get CFB Drive data from the 2020 CFB season.
187        print("Get CFB Drive data from the 2020 CFB season.")
188        json_data = get_cfbd_drives_info(
189            api_key=cfbd_key,
190            season=2020
191        )
192        print(json_data)
193        time.sleep(5)
194
195        # Get CFB Drive data from week 10 of the 2020 CFB season.
196        print("Get CFB Drive data from week 10 of the 2020 CFB season.")
197        json_data = get_cfbd_drives_info(
198            api_key=cfbd_key,
199            season=2020,
200            week=10
201        )
202        print(json_data)
203        time.sleep(5)
204
205        # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats
206        # Football Team.
207        print(
208            "Get CFB Drive data from games involving " +
209            "the 2020 Cincinnati Bearcats Football Team."
210        )
211        json_data = get_cfbd_drives_info(
212            api_key=cfbd_key,
213            season=2020,
214            team="Cincinnati"
215        )
216        print(json_data)
217        time.sleep(5)
218
219        # Get CFB Drive data from games involving the 2020 Ohio Bobcats
220        # Football Team, when Ohio was on offense.
221        print(
222            "Get CFB Drive data from games involving " +
223            "the 2020 Ohio Bobcats Football Team, when Ohio was on offense."
224        )
225        json_data = get_cfbd_drives_info(
226            api_key=cfbd_key,
227            season=2020,
228            offensive_team="Ohio"
229        )
230        print(json_data)
231        time.sleep(5)
232
233        # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes
234        # Football Team, when Ohio was on offense.
235        print(
236            "Get CFB Drive data from games involving " +
237            "the 2020 Ohio State Buckeyes Football Team, " +
238            "when Ohio State was on defense."
239        )
240        json_data = get_cfbd_drives_info(
241            api_key=cfbd_key,
242            season=2020,
243            defensive_team="Ohio State"
244        )
245        print(json_data)
246        time.sleep(5)
247
248        # Get CFB Drive data from Big 12 games in the 2020 CFB season.
249        print(
250            "Get CFB Drive data from games involving " +
251            "the 2020 Ohio State Buckeyes Football Team, " +
252            "when Ohio State was on defense."
253        )
254        json_data = get_cfbd_drives_info(
255            api_key=cfbd_key,
256            season=2020,
257            conference="B12"
258        )
259        print(json_data)
260        time.sleep(5)
261
262        # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,
263        # where the Big 10 team was on offense.
264        print(
265            "Get CFB Drive data from games involving " +
266            "the 2020 Ohio State Buckeyes Football Team, " +
267            "when Ohio State was on defense."
268        )
269        json_data = get_cfbd_drives_info(
270            api_key=cfbd_key,
271            season=2020,
272            offensive_conference="B1G"
273        )
274        print(json_data)
275        time.sleep(5)
276
277        # Get CFB Drive data from  Mid-American Conference (MAC) games
278        # in the 2020 CFB season, where the MAC team was on offense.
279        print(
280            "Get CFB Drive data from games involving " +
281            "the 2020 Ohio State Buckeyes Football Team, " +
282            "when Ohio State was on defense."
283        )
284        json_data = get_cfbd_drives_info(
285            api_key=cfbd_key,
286            season=2020,
287            defensive_conference="MAC"
288        )
289        print(json_data)
290        time.sleep(5)
291
292        # Get CFB Drive data from Football Championship Subdivision (FCS) games
293        # in week 3 of the 2020 CFB season,
294        # where the MAC team was on offense.
295        print(
296            "Get CFB Drive data from games involving " +
297            "the 2020 Ohio State Buckeyes Football Team, " +
298            "when Ohio State was on defense."
299        )
300        json_data = get_cfbd_drives_info(
301            api_key=cfbd_key,
302            season=2020,
303            week=3,
304            ncaa_division="fcs"
305        )
306        print(json_data)
307        time.sleep(5)
308
309        # You can also tell this function to just return the API call as
310        # a Dictionary (read: JSON) object.
311        print(
312            "You can also tell this function to just return the API call " +
313            "as a Dictionary (read: JSON) object."
314        )
315        json_data = get_cfbd_drives_info(
316            season=2020,
317            week=10,
318            api_key=cfbd_key,
319            return_as_dict=True
320        )
321        print(json_data)
322
323    else:
324        # Alternatively, if the CFBD API key exists in this python environment,
325        # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),
326        # you could just call these functions directly,
327        # without setting the API key in the script.
328        print(
329            "Using the user's API key supposedly loaded " +
330            "into this python environment for this example."
331        )
332
333        # Get CFB Drive data from the 2020 CFB season.
334        print("Get CFB Drive data from the 2020 CFB season.")
335        json_data = get_cfbd_drives_info(
336            season=2020
337        )
338        print(json_data)
339        time.sleep(5)
340
341        # Get CFB Drive data from week 10 of the 2020 CFB season.
342        print("Get CFB Drive data from week 10 of the 2020 CFB season.")
343        json_data = get_cfbd_drives_info(
344            season=2020,
345            week=10
346        )
347        print(json_data)
348        time.sleep(5)
349
350        # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats
351        # Football Team.
352        print(
353            "Get CFB Drive data from games involving " +
354            "the 2020 Cincinnati Bearcats Football Team."
355        )
356        json_data = get_cfbd_drives_info(
357            season=2020,
358            team="Cincinnati"
359        )
360        print(json_data)
361        time.sleep(5)
362
363        # Get CFB Drive data from games involving the 2020 Ohio Bobcats
364        # Football Team, when Ohio was on offense.
365        print(
366            "Get CFB Drive data from games involving " +
367            "the 2020 Ohio Bobcats Football Team, when Ohio was on offense."
368        )
369        json_data = get_cfbd_drives_info(
370            season=2020,
371            offensive_team="Ohio"
372        )
373        print(json_data)
374        time.sleep(5)
375
376        # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes
377        # Football Team, when Ohio was on offense.
378        print(
379            "Get CFB Drive data from games involving " +
380            "the 2020 Ohio State Buckeyes Football Team, " +
381            "when Ohio State was on defense."
382        )
383        json_data = get_cfbd_drives_info(
384            season=2020,
385            defensive_team="Ohio State"
386        )
387        print(json_data)
388        time.sleep(5)
389
390        # Get CFB Drive data from Big 12 games in the 2020 CFB season.
391        print(
392            "Get CFB Drive data from games involving " +
393            "the 2020 Ohio State Buckeyes Football Team, " +
394            "when Ohio State was on defense."
395        )
396        json_data = get_cfbd_drives_info(
397            season=2020,
398            conference="B12"
399        )
400        print(json_data)
401        time.sleep(5)
402
403        # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,
404        # where the Big 10 team was on offense.
405        print(
406            "Get CFB Drive data from games involving " +
407            "the 2020 Ohio State Buckeyes Football Team, " +
408            "when Ohio State was on defense."
409        )
410        json_data = get_cfbd_drives_info(
411            season=2020,
412            offensive_conference="B1G"
413        )
414        print(json_data)
415        time.sleep(5)
416
417        # Get CFB Drive data from  Mid-American Conference (MAC) games
418        # in the 2020 CFB season, where the MAC team was on offense.
419        print(
420            "Get CFB Drive data from games involving " +
421            "the 2020 Ohio State Buckeyes Football Team, " +
422            "when Ohio State was on defense."
423        )
424        json_data = get_cfbd_drives_info(
425            season=2020,
426            defensive_conference="MAC"
427        )
428        print(json_data)
429        time.sleep(5)
430
431        # Get CFB Drive data from Football Championship Subdivision (FCS) games
432        # in week 3 of the 2020 CFB season,
433        # where the MAC team was on offense.
434        print(
435            "Get CFB Drive data from games involving " +
436            "the 2020 Ohio State Buckeyes Football Team, " +
437            "when Ohio State was on defense."
438        )
439        json_data = get_cfbd_drives_info(
440            season=2020,
441            week=3,
442            ncaa_division="fcs"
443        )
444        print(json_data)
445        time.sleep(5)
446
447        # You can also tell this function to just return the API call as
448        # a Dictionary (read: JSON) object.
449        print(
450            "You can also tell this function to just return the API call " +
451            "as a Dictionary (read: JSON) object."
452        )
453        json_data = get_cfbd_drives_info(
454            season=2020,
455            week=10,
456            return_as_dict=True
457        )
458        print(json_data)
459
460    ```
461
462    Returns
463    ----------
464    A pandas `DataFrame` object with CFB drive data,
465    or (if `return_as_dict` is set to `True`)
466    a dictionary object with CFB drive data.
467
468    """
469    now = datetime.now()
470    cfb_drives_df = pd.DataFrame()
471    # row_df = pd.DataFrame()
472    url = "https://api.collegefootballdata.com/drives"
473
474    # Input validation
475    ##########################################################################
476
477    # `year` to `season`
478    if season is not None and year is not None and (year is not season):
479        raise ValueError(
480            "When using this function, "
481            + "please specify a season in EITHER `year` or `season`."
482        )
483    if season is not None:
484        pass
485    elif year is not None:
486        season = year
487    else:
488        raise ValueError("No year/season inputted for this function.")
489
490    # `offense` to `offensive_team`
491    if (
492        offense is not None
493        and offensive_team is not None
494        and (offense is not offensive_team)
495    ):
496        raise ValueError(
497            "When using this function, "
498            + "please specify a season in EITHER "
499            + "`offense` or `offensive_team`."
500        )
501    if offensive_team is not None:
502        pass
503    elif offense is not None:
504        offensive_team = offense
505
506    # `defense` to `defensive_team`
507    if (
508        defense is not None
509        and defensive_team is not None
510        and (defense is not defensive_team)
511    ):
512        raise ValueError(
513            "When using this function, "
514            + "please specify a season in EITHER "
515            + "`defense` or `defensive_team`."
516        )
517    if defensive_team is not None:
518        pass
519    elif defense is not None:
520        defensive_team = defense
521
522    # `classification` to `ncaa_division`
523    if (
524        classification is not None
525        and ncaa_division is not None
526        and (classification is not ncaa_division)
527    ):
528        raise ValueError(
529            "When using this function, "
530            + "please specify a season in EITHER "
531            + "`classification` or `ncaa_division`."
532        )
533    if ncaa_division is not None:
534        pass
535    elif defense is not None:
536        ncaa_division = classification
537
538    if api_key is not None:
539        real_api_key = api_key
540        del api_key
541    else:
542        real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir)
543
544    if real_api_key == "tigersAreAwesome":
545        raise ValueError(
546            "You actually need to change `cfbd_key` to your CFBD API key."
547        )
548    elif "Bearer " in real_api_key:
549        pass
550    elif "Bearer" in real_api_key:
551        real_api_key = real_api_key.replace("Bearer", "Bearer ")
552    else:
553        real_api_key = "Bearer " + real_api_key
554
555    if season is None:
556        # This should never happen without user tampering, but if it does,
557        # we need to raise an error,
558        # because the CFBD API will refuse this call without a valid season.
559        raise SystemError(
560            "I don't know how, I don't know why, "
561            + "but you managed to call this function "
562            + "while `season` was `None` (NULL),"
563            + " and the function got to this point in the code."
564            + "\nIf you have a GitHub account, "
565            + "please raise an issue on this python package's GitHub page:\n"
566            + "https://github.com/armstjc/cfbd-json-py/issues"
567        )
568    elif season > (now.year + 1):
569        raise ValueError(f"`season` cannot be greater than {season}.")
570    elif season < 1869:
571        raise ValueError("`season` cannot be less than 1869.")
572
573    if season_type != "regular" and season_type != "postseason":
574        raise ValueError(
575            '`season_type` must be set to either ' +
576            '"regular" or "postseason" for this function to work.'
577        )
578
579    if (
580        ncaa_division.lower() == "fbs"
581        or ncaa_division.lower() == "fcs"
582        or ncaa_division.lower() == "ii"
583        or ncaa_division.lower() == "iii"
584    ):
585        pass
586    else:
587        raise ValueError(
588            "An invalid NCAA Division was inputted when calling this function."
589            + '\nValid inputs are:\n-"fbs"\n-"fcs"\n-"ii"\n-"iii"'
590            + f"\n\nYou entered:\n{ncaa_division}"
591        )
592
593    # URL builder
594    ##########################################################################
595
596    # Required by API
597    url += f"?seasonType={season_type}"
598
599    url += f"&year={season}"
600
601    if week is not None:
602        url += f"&week={week}"
603
604    if team is not None:
605        url += f"&team={team}"
606
607    if offensive_team is not None:
608        url += f"&offense={offensive_team}"
609
610    if defensive_team is not None:
611        url += f"&defense={defensive_team}"
612
613    if conference is not None:
614        url += f"&conference={conference}"
615
616    if offensive_conference is not None:
617        url += f"&offenseConference={offensive_conference}"
618
619    if defensive_conference is not None:
620        url += f"&defenseConference={defensive_conference}"
621
622    if ncaa_division is not None:
623        url += f"&classification={ncaa_division.lower()}"
624
625    headers = {
626        "Authorization": f"{real_api_key}",
627        "accept": "application/json"
628    }
629
630    response = requests.get(url, headers=headers)
631
632    if response.status_code == 200:
633        pass
634    elif response.status_code == 401:
635        raise ConnectionRefusedError(
636            "Could not connect. The connection was refused." +
637            "\nHTTP Status Code 401."
638        )
639    else:
640        raise ConnectionError(
641            f"Could not connect.\nHTTP Status code {response.status_code}"
642        )
643
644    json_data = response.json()
645
646    if return_as_dict is True:
647        return json_data
648
649    cfb_drives_df = pd.json_normalize(json_data)
650    cfb_drives_df.to_csv("test.csv")
651    # print(cfb_drives_df.columns)
652    cfb_drives_df.rename(
653        columns={
654            "offense": "offense_team_name",
655            "offense_conference": "offense_conference_name",
656            "defense": "defense_name",
657            "defense_conference": "defense_conference_name",
658            "id": "drive_id",
659            "scoring": "is_scoring_drive",
660            "start_time.minutes": "start_time_minutes",
661            "start_time.seconds": "start_time_seconds",
662            "end_time.minutes": "end_time_minutes",
663            "end_time.seconds": "end_time_seconds",
664            "elapsed.minutes": "elapsed_minutes",
665            "elapsed.seconds": "elapsed_seconds",
666        },
667        inplace=True,
668    )
669    if len(cfb_drives_df) == 0:
670        logging.error(
671            "The CFBD API accepted your inputs, "
672            + "but found no data within your specified input parameters."
673            + " Please double check your input parameters."
674        )
675
676    return cfb_drives_df
def get_cfbd_drives_info( api_key: str = None, api_key_dir: str = None, season: int = None, season_type: str = 'regular', week: int = None, team: str = None, offensive_team: str = None, defensive_team: str = None, conference: str = None, offensive_conference: str = None, defensive_conference: str = None, ncaa_division: str = 'fbs', year: int = None, offense: str = None, defense: str = None, classification: str = None, return_as_dict: bool = False):
 18def get_cfbd_drives_info(
 19    api_key: str = None,
 20    api_key_dir: str = None,
 21    season: int = None,
 22    season_type: str = "regular",
 23    week: int = None,
 24    team: str = None,
 25    offensive_team: str = None,
 26    defensive_team: str = None,
 27    conference: str = None,
 28    offensive_conference: str = None,
 29    defensive_conference: str = None,
 30    ncaa_division: str = "fbs",
 31    year: int = None,
 32    offense: str = None,
 33    defense: str = None,
 34    classification: str = None,
 35    return_as_dict: bool = False,
 36):
 37    """
 38    Retrieves a list of CFB drives from the CFBD API.
 39
 40    Parameters
 41    ----------
 42    `season` (int, mandatory):
 43        Required argument.
 44        Specifies the season you want CFB drive information from.
 45        This must be specified, otherwise this package, and by extension
 46        the CFBD API, will not accept the request to get CFB drive information.
 47
 48    `api_key` (str, optional):
 49        Semi-optional argument.
 50        If `api_key` is null, this function will attempt to load a CFBD API key
 51        from the python environment, or from a file on this computer.
 52        If `api_key` is not null,
 53        this function will automatically assume that the
 54        inputted `api_key` is a valid CFBD API key.
 55
 56    `api_key_dir` (str, optional):
 57        Optional argument.
 58        If `api_key` is set to am empty string, this variable is ignored.
 59        If `api_key_dir` is null, and `api_key` is null,
 60        this function will try to find
 61        a CFBD API key file in this user's home directory.
 62        If `api_key_dir` is set to a string, and `api_key` is null,
 63        this function will assume that `api_key_dir` is a directory,
 64        and will try to find a CFBD API key file in that directory.
 65
 66    `season_type` (str, semi-optional):
 67        Semi-optional argument.
 68        By default, this will be set to "regular", for the CFB regular season.
 69        If you want CFB drive data for non-regular season games,
 70        set `season_type` to "postseason".
 71        If `season_type` is set to anything but "regular" or "postseason",
 72        a `ValueError()` will be raised.
 73
 74    `week` (int, optional):
 75        Optional argument.
 76        If `week` is set to an integer, this function will attempt
 77        to load CFB drive data from games in that season, and that week.
 78
 79    `team` (str, optional):
 80        Optional argument.
 81        If you only want CFB drive data for a team,
 82        regardless if they are the home/away team,
 83        set `team` to the name of the team you want CFB drive data from.
 84
 85    `offensive_team` (str, optional):
 86        Optional argument.
 87        If you only want CFB drive data from a team, while they are on offense,
 88        regardless if they are the home/away team,
 89        set `team` to the name of the team you want CFB drive data from.
 90
 91    `defensive_team` (str, optional):
 92        Optional argument.
 93        If you only want CFB drive data from a team, while they are on defense,
 94        regardless if they are the home/away team,
 95        set `team` to the name of the team you want CFB drive data from.
 96
 97    `conference` (str, optional):
 98        Optional argument.
 99        If you only want CFB drive data from games
100        involving teams from a specific conference,
101        set `conference` to the abbreviation
102        of the conference you want CFB drive data from.
103        For a list of conferences,
104        use the `cfbd_json_py.conferences.get_cfbd_conference_info()`
105        function.
106
107    `offensive_conference` (str, optional):
108        Optional argument.
109        If you only want CFB drive data from games
110        where the offensive team is from a specific conference,
111        set `conference` to the abbreviation
112        of the conference you want CFB drive data from.
113        For a list of conferences,
114        use the `cfbd_json_py.conferences.get_cfbd_conference_info()`
115        function.
116
117    `defensive_conference` (str, optional):
118        Optional argument.
119        If you only want CFB drive data from games
120        where the defensive team is from a specific conference,
121        set `conference` to the abbreviation
122        of the conference you want CFB drive data from.
123        For a list of conferences,
124        use the `cfbd_json_py.conferences.get_cfbd_conference_info()`
125        function.
126
127    `ncaa_division` (str, semi-optional):
128        Semi-optional argument.
129        By default, `ncaa_division` will be set to "fbs",
130        short for the Football Bowl Subdivision (FBS),
131        formerly known as D1-A (read as "division one single A"),
132        the highest level in the NCAA football pyramid,
133        where teams can scholarship up to 85 players
134        on their football team solely for athletic ability,
135        and often have the largest athletics budgets
136        within the NCAA.
137
138        Other valid inputs are:
139        - "fcs": Football Championship Subdivision (FCS),
140            formerly known as D1-AA (read as "division one double A").
141            An FCS school is still in the 1st division of the NCAA,
142            making them eligible for the March Madness tournament,
143            but may not have the resources to compete at the FBS level
144            at this time. FCS schools are limited to 63 athletic scholarships
145            for football.
146        - "ii": NCAA Division II. Schools in this and D3 are not
147            eligible for the March Madness tournament,
148            and are limited to 36 athletic scholarships
149            for their football team.
150        - "iii": NCAA Division III. The largest single division within the
151            NCAA football pyramid.
152            D3 schools have the distinction of being part of
153            the only NCAA division that cannot give out scholarships solely
154            for athletic ability.
155
156    `offense` (str):
157        Alternative keyword for `offensive_team`
158
159    `defense` (str):
160        Alternative keyword for `defensive_team`
161
162    `classification` (str):
163        Alternative keyword for `ncaa_division`
164
165    `return_as_dict` (bool, semi-optional):
166        Semi-optional argument.
167        If you want this function to return the data
168        as a dictionary (read: JSON object),
169        instead of a pandas `DataFrame` object,
170        set `return_as_dict` to `True`.
171
172    Usage
173    ----------
174    ```
175    import time
176
177    from cfbd_json_py.drives import get_cfbd_drives_info
178
179    cfbd_key = "tigersAreAwesome"  # placeholder for your CFBD API Key.
180
181    if cfbd_key is not "tigersAreAwesome":
182        print(
183            "Using the user's API key declared in this script " +
184            "for this example."
185        )
186
187        # Get CFB Drive data from the 2020 CFB season.
188        print("Get CFB Drive data from the 2020 CFB season.")
189        json_data = get_cfbd_drives_info(
190            api_key=cfbd_key,
191            season=2020
192        )
193        print(json_data)
194        time.sleep(5)
195
196        # Get CFB Drive data from week 10 of the 2020 CFB season.
197        print("Get CFB Drive data from week 10 of the 2020 CFB season.")
198        json_data = get_cfbd_drives_info(
199            api_key=cfbd_key,
200            season=2020,
201            week=10
202        )
203        print(json_data)
204        time.sleep(5)
205
206        # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats
207        # Football Team.
208        print(
209            "Get CFB Drive data from games involving " +
210            "the 2020 Cincinnati Bearcats Football Team."
211        )
212        json_data = get_cfbd_drives_info(
213            api_key=cfbd_key,
214            season=2020,
215            team="Cincinnati"
216        )
217        print(json_data)
218        time.sleep(5)
219
220        # Get CFB Drive data from games involving the 2020 Ohio Bobcats
221        # Football Team, when Ohio was on offense.
222        print(
223            "Get CFB Drive data from games involving " +
224            "the 2020 Ohio Bobcats Football Team, when Ohio was on offense."
225        )
226        json_data = get_cfbd_drives_info(
227            api_key=cfbd_key,
228            season=2020,
229            offensive_team="Ohio"
230        )
231        print(json_data)
232        time.sleep(5)
233
234        # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes
235        # Football Team, when Ohio was on offense.
236        print(
237            "Get CFB Drive data from games involving " +
238            "the 2020 Ohio State Buckeyes Football Team, " +
239            "when Ohio State was on defense."
240        )
241        json_data = get_cfbd_drives_info(
242            api_key=cfbd_key,
243            season=2020,
244            defensive_team="Ohio State"
245        )
246        print(json_data)
247        time.sleep(5)
248
249        # Get CFB Drive data from Big 12 games in the 2020 CFB season.
250        print(
251            "Get CFB Drive data from games involving " +
252            "the 2020 Ohio State Buckeyes Football Team, " +
253            "when Ohio State was on defense."
254        )
255        json_data = get_cfbd_drives_info(
256            api_key=cfbd_key,
257            season=2020,
258            conference="B12"
259        )
260        print(json_data)
261        time.sleep(5)
262
263        # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,
264        # where the Big 10 team was on offense.
265        print(
266            "Get CFB Drive data from games involving " +
267            "the 2020 Ohio State Buckeyes Football Team, " +
268            "when Ohio State was on defense."
269        )
270        json_data = get_cfbd_drives_info(
271            api_key=cfbd_key,
272            season=2020,
273            offensive_conference="B1G"
274        )
275        print(json_data)
276        time.sleep(5)
277
278        # Get CFB Drive data from  Mid-American Conference (MAC) games
279        # in the 2020 CFB season, where the MAC team was on offense.
280        print(
281            "Get CFB Drive data from games involving " +
282            "the 2020 Ohio State Buckeyes Football Team, " +
283            "when Ohio State was on defense."
284        )
285        json_data = get_cfbd_drives_info(
286            api_key=cfbd_key,
287            season=2020,
288            defensive_conference="MAC"
289        )
290        print(json_data)
291        time.sleep(5)
292
293        # Get CFB Drive data from Football Championship Subdivision (FCS) games
294        # in week 3 of the 2020 CFB season,
295        # where the MAC team was on offense.
296        print(
297            "Get CFB Drive data from games involving " +
298            "the 2020 Ohio State Buckeyes Football Team, " +
299            "when Ohio State was on defense."
300        )
301        json_data = get_cfbd_drives_info(
302            api_key=cfbd_key,
303            season=2020,
304            week=3,
305            ncaa_division="fcs"
306        )
307        print(json_data)
308        time.sleep(5)
309
310        # You can also tell this function to just return the API call as
311        # a Dictionary (read: JSON) object.
312        print(
313            "You can also tell this function to just return the API call " +
314            "as a Dictionary (read: JSON) object."
315        )
316        json_data = get_cfbd_drives_info(
317            season=2020,
318            week=10,
319            api_key=cfbd_key,
320            return_as_dict=True
321        )
322        print(json_data)
323
324    else:
325        # Alternatively, if the CFBD API key exists in this python environment,
326        # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),
327        # you could just call these functions directly,
328        # without setting the API key in the script.
329        print(
330            "Using the user's API key supposedly loaded " +
331            "into this python environment for this example."
332        )
333
334        # Get CFB Drive data from the 2020 CFB season.
335        print("Get CFB Drive data from the 2020 CFB season.")
336        json_data = get_cfbd_drives_info(
337            season=2020
338        )
339        print(json_data)
340        time.sleep(5)
341
342        # Get CFB Drive data from week 10 of the 2020 CFB season.
343        print("Get CFB Drive data from week 10 of the 2020 CFB season.")
344        json_data = get_cfbd_drives_info(
345            season=2020,
346            week=10
347        )
348        print(json_data)
349        time.sleep(5)
350
351        # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats
352        # Football Team.
353        print(
354            "Get CFB Drive data from games involving " +
355            "the 2020 Cincinnati Bearcats Football Team."
356        )
357        json_data = get_cfbd_drives_info(
358            season=2020,
359            team="Cincinnati"
360        )
361        print(json_data)
362        time.sleep(5)
363
364        # Get CFB Drive data from games involving the 2020 Ohio Bobcats
365        # Football Team, when Ohio was on offense.
366        print(
367            "Get CFB Drive data from games involving " +
368            "the 2020 Ohio Bobcats Football Team, when Ohio was on offense."
369        )
370        json_data = get_cfbd_drives_info(
371            season=2020,
372            offensive_team="Ohio"
373        )
374        print(json_data)
375        time.sleep(5)
376
377        # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes
378        # Football Team, when Ohio was on offense.
379        print(
380            "Get CFB Drive data from games involving " +
381            "the 2020 Ohio State Buckeyes Football Team, " +
382            "when Ohio State was on defense."
383        )
384        json_data = get_cfbd_drives_info(
385            season=2020,
386            defensive_team="Ohio State"
387        )
388        print(json_data)
389        time.sleep(5)
390
391        # Get CFB Drive data from Big 12 games in the 2020 CFB season.
392        print(
393            "Get CFB Drive data from games involving " +
394            "the 2020 Ohio State Buckeyes Football Team, " +
395            "when Ohio State was on defense."
396        )
397        json_data = get_cfbd_drives_info(
398            season=2020,
399            conference="B12"
400        )
401        print(json_data)
402        time.sleep(5)
403
404        # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,
405        # where the Big 10 team was on offense.
406        print(
407            "Get CFB Drive data from games involving " +
408            "the 2020 Ohio State Buckeyes Football Team, " +
409            "when Ohio State was on defense."
410        )
411        json_data = get_cfbd_drives_info(
412            season=2020,
413            offensive_conference="B1G"
414        )
415        print(json_data)
416        time.sleep(5)
417
418        # Get CFB Drive data from  Mid-American Conference (MAC) games
419        # in the 2020 CFB season, where the MAC team was on offense.
420        print(
421            "Get CFB Drive data from games involving " +
422            "the 2020 Ohio State Buckeyes Football Team, " +
423            "when Ohio State was on defense."
424        )
425        json_data = get_cfbd_drives_info(
426            season=2020,
427            defensive_conference="MAC"
428        )
429        print(json_data)
430        time.sleep(5)
431
432        # Get CFB Drive data from Football Championship Subdivision (FCS) games
433        # in week 3 of the 2020 CFB season,
434        # where the MAC team was on offense.
435        print(
436            "Get CFB Drive data from games involving " +
437            "the 2020 Ohio State Buckeyes Football Team, " +
438            "when Ohio State was on defense."
439        )
440        json_data = get_cfbd_drives_info(
441            season=2020,
442            week=3,
443            ncaa_division="fcs"
444        )
445        print(json_data)
446        time.sleep(5)
447
448        # You can also tell this function to just return the API call as
449        # a Dictionary (read: JSON) object.
450        print(
451            "You can also tell this function to just return the API call " +
452            "as a Dictionary (read: JSON) object."
453        )
454        json_data = get_cfbd_drives_info(
455            season=2020,
456            week=10,
457            return_as_dict=True
458        )
459        print(json_data)
460
461    ```
462
463    Returns
464    ----------
465    A pandas `DataFrame` object with CFB drive data,
466    or (if `return_as_dict` is set to `True`)
467    a dictionary object with CFB drive data.
468
469    """
470    now = datetime.now()
471    cfb_drives_df = pd.DataFrame()
472    # row_df = pd.DataFrame()
473    url = "https://api.collegefootballdata.com/drives"
474
475    # Input validation
476    ##########################################################################
477
478    # `year` to `season`
479    if season is not None and year is not None and (year is not season):
480        raise ValueError(
481            "When using this function, "
482            + "please specify a season in EITHER `year` or `season`."
483        )
484    if season is not None:
485        pass
486    elif year is not None:
487        season = year
488    else:
489        raise ValueError("No year/season inputted for this function.")
490
491    # `offense` to `offensive_team`
492    if (
493        offense is not None
494        and offensive_team is not None
495        and (offense is not offensive_team)
496    ):
497        raise ValueError(
498            "When using this function, "
499            + "please specify a season in EITHER "
500            + "`offense` or `offensive_team`."
501        )
502    if offensive_team is not None:
503        pass
504    elif offense is not None:
505        offensive_team = offense
506
507    # `defense` to `defensive_team`
508    if (
509        defense is not None
510        and defensive_team is not None
511        and (defense is not defensive_team)
512    ):
513        raise ValueError(
514            "When using this function, "
515            + "please specify a season in EITHER "
516            + "`defense` or `defensive_team`."
517        )
518    if defensive_team is not None:
519        pass
520    elif defense is not None:
521        defensive_team = defense
522
523    # `classification` to `ncaa_division`
524    if (
525        classification is not None
526        and ncaa_division is not None
527        and (classification is not ncaa_division)
528    ):
529        raise ValueError(
530            "When using this function, "
531            + "please specify a season in EITHER "
532            + "`classification` or `ncaa_division`."
533        )
534    if ncaa_division is not None:
535        pass
536    elif defense is not None:
537        ncaa_division = classification
538
539    if api_key is not None:
540        real_api_key = api_key
541        del api_key
542    else:
543        real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir)
544
545    if real_api_key == "tigersAreAwesome":
546        raise ValueError(
547            "You actually need to change `cfbd_key` to your CFBD API key."
548        )
549    elif "Bearer " in real_api_key:
550        pass
551    elif "Bearer" in real_api_key:
552        real_api_key = real_api_key.replace("Bearer", "Bearer ")
553    else:
554        real_api_key = "Bearer " + real_api_key
555
556    if season is None:
557        # This should never happen without user tampering, but if it does,
558        # we need to raise an error,
559        # because the CFBD API will refuse this call without a valid season.
560        raise SystemError(
561            "I don't know how, I don't know why, "
562            + "but you managed to call this function "
563            + "while `season` was `None` (NULL),"
564            + " and the function got to this point in the code."
565            + "\nIf you have a GitHub account, "
566            + "please raise an issue on this python package's GitHub page:\n"
567            + "https://github.com/armstjc/cfbd-json-py/issues"
568        )
569    elif season > (now.year + 1):
570        raise ValueError(f"`season` cannot be greater than {season}.")
571    elif season < 1869:
572        raise ValueError("`season` cannot be less than 1869.")
573
574    if season_type != "regular" and season_type != "postseason":
575        raise ValueError(
576            '`season_type` must be set to either ' +
577            '"regular" or "postseason" for this function to work.'
578        )
579
580    if (
581        ncaa_division.lower() == "fbs"
582        or ncaa_division.lower() == "fcs"
583        or ncaa_division.lower() == "ii"
584        or ncaa_division.lower() == "iii"
585    ):
586        pass
587    else:
588        raise ValueError(
589            "An invalid NCAA Division was inputted when calling this function."
590            + '\nValid inputs are:\n-"fbs"\n-"fcs"\n-"ii"\n-"iii"'
591            + f"\n\nYou entered:\n{ncaa_division}"
592        )
593
594    # URL builder
595    ##########################################################################
596
597    # Required by API
598    url += f"?seasonType={season_type}"
599
600    url += f"&year={season}"
601
602    if week is not None:
603        url += f"&week={week}"
604
605    if team is not None:
606        url += f"&team={team}"
607
608    if offensive_team is not None:
609        url += f"&offense={offensive_team}"
610
611    if defensive_team is not None:
612        url += f"&defense={defensive_team}"
613
614    if conference is not None:
615        url += f"&conference={conference}"
616
617    if offensive_conference is not None:
618        url += f"&offenseConference={offensive_conference}"
619
620    if defensive_conference is not None:
621        url += f"&defenseConference={defensive_conference}"
622
623    if ncaa_division is not None:
624        url += f"&classification={ncaa_division.lower()}"
625
626    headers = {
627        "Authorization": f"{real_api_key}",
628        "accept": "application/json"
629    }
630
631    response = requests.get(url, headers=headers)
632
633    if response.status_code == 200:
634        pass
635    elif response.status_code == 401:
636        raise ConnectionRefusedError(
637            "Could not connect. The connection was refused." +
638            "\nHTTP Status Code 401."
639        )
640    else:
641        raise ConnectionError(
642            f"Could not connect.\nHTTP Status code {response.status_code}"
643        )
644
645    json_data = response.json()
646
647    if return_as_dict is True:
648        return json_data
649
650    cfb_drives_df = pd.json_normalize(json_data)
651    cfb_drives_df.to_csv("test.csv")
652    # print(cfb_drives_df.columns)
653    cfb_drives_df.rename(
654        columns={
655            "offense": "offense_team_name",
656            "offense_conference": "offense_conference_name",
657            "defense": "defense_name",
658            "defense_conference": "defense_conference_name",
659            "id": "drive_id",
660            "scoring": "is_scoring_drive",
661            "start_time.minutes": "start_time_minutes",
662            "start_time.seconds": "start_time_seconds",
663            "end_time.minutes": "end_time_minutes",
664            "end_time.seconds": "end_time_seconds",
665            "elapsed.minutes": "elapsed_minutes",
666            "elapsed.seconds": "elapsed_seconds",
667        },
668        inplace=True,
669    )
670    if len(cfb_drives_df) == 0:
671        logging.error(
672            "The CFBD API accepted your inputs, "
673            + "but found no data within your specified input parameters."
674            + " Please double check your input parameters."
675        )
676
677    return cfb_drives_df

Retrieves a list of CFB drives from the CFBD API.

Parameters

season (int, mandatory): Required argument. Specifies the season you want CFB drive information from. This must be specified, otherwise this package, and by extension the CFBD API, will not accept the request to get CFB drive information.

api_key (str, optional): Semi-optional argument. If api_key is null, this function will attempt to load a CFBD API key from the python environment, or from a file on this computer. If api_key is not null, this function will automatically assume that the inputted api_key is a valid CFBD API key.

api_key_dir (str, optional): Optional argument. If api_key is set to am empty string, this variable is ignored. If api_key_dir is null, and api_key is null, this function will try to find a CFBD API key file in this user's home directory. If api_key_dir is set to a string, and api_key is null, this function will assume that api_key_dir is a directory, and will try to find a CFBD API key file in that directory.

season_type (str, semi-optional): Semi-optional argument. By default, this will be set to "regular", for the CFB regular season. If you want CFB drive data for non-regular season games, set season_type to "postseason". If season_type is set to anything but "regular" or "postseason", a ValueError() will be raised.

week (int, optional): Optional argument. If week is set to an integer, this function will attempt to load CFB drive data from games in that season, and that week.

team (str, optional): Optional argument. If you only want CFB drive data for a team, regardless if they are the home/away team, set team to the name of the team you want CFB drive data from.

offensive_team (str, optional): Optional argument. If you only want CFB drive data from a team, while they are on offense, regardless if they are the home/away team, set team to the name of the team you want CFB drive data from.

defensive_team (str, optional): Optional argument. If you only want CFB drive data from a team, while they are on defense, regardless if they are the home/away team, set team to the name of the team you want CFB drive data from.

conference (str, optional): Optional argument. If you only want CFB drive data from games involving teams from a specific conference, set conference to the abbreviation of the conference you want CFB drive data from. For a list of conferences, use the cfbd_json_py.conferences.get_cfbd_conference_info() function.

offensive_conference (str, optional): Optional argument. If you only want CFB drive data from games where the offensive team is from a specific conference, set conference to the abbreviation of the conference you want CFB drive data from. For a list of conferences, use the cfbd_json_py.conferences.get_cfbd_conference_info() function.

defensive_conference (str, optional): Optional argument. If you only want CFB drive data from games where the defensive team is from a specific conference, set conference to the abbreviation of the conference you want CFB drive data from. For a list of conferences, use the cfbd_json_py.conferences.get_cfbd_conference_info() function.

ncaa_division (str, semi-optional): Semi-optional argument. By default, ncaa_division will be set to "fbs", short for the Football Bowl Subdivision (FBS), formerly known as D1-A (read as "division one single A"), the highest level in the NCAA football pyramid, where teams can scholarship up to 85 players on their football team solely for athletic ability, and often have the largest athletics budgets within the NCAA.

Other valid inputs are:
- "fcs": Football Championship Subdivision (FCS),
    formerly known as D1-AA (read as "division one double A").
    An FCS school is still in the 1st division of the NCAA,
    making them eligible for the March Madness tournament,
    but may not have the resources to compete at the FBS level
    at this time. FCS schools are limited to 63 athletic scholarships
    for football.
- "ii": NCAA Division II. Schools in this and D3 are not
    eligible for the March Madness tournament,
    and are limited to 36 athletic scholarships
    for their football team.
- "iii": NCAA Division III. The largest single division within the
    NCAA football pyramid.
    D3 schools have the distinction of being part of
    the only NCAA division that cannot give out scholarships solely
    for athletic ability.

offense (str): Alternative keyword for offensive_team

defense (str): Alternative keyword for defensive_team

classification (str): Alternative keyword for ncaa_division

return_as_dict (bool, semi-optional): Semi-optional argument. If you want this function to return the data as a dictionary (read: JSON object), instead of a pandas DataFrame object, set return_as_dict to True.

Usage

import time

from cfbd_json_py.drives import get_cfbd_drives_info

cfbd_key = "tigersAreAwesome"  # placeholder for your CFBD API Key.

if cfbd_key is not "tigersAreAwesome":
    print(
        "Using the user's API key declared in this script " +
        "for this example."
    )

    # Get CFB Drive data from the 2020 CFB season.
    print("Get CFB Drive data from the 2020 CFB season.")
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from week 10 of the 2020 CFB season.
    print("Get CFB Drive data from week 10 of the 2020 CFB season.")
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        week=10
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats
    # Football Team.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Cincinnati Bearcats Football Team."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        team="Cincinnati"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from games involving the 2020 Ohio Bobcats
    # Football Team, when Ohio was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio Bobcats Football Team, when Ohio was on offense."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        offensive_team="Ohio"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes
    # Football Team, when Ohio was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        defensive_team="Ohio State"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from Big 12 games in the 2020 CFB season.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        conference="B12"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,
    # where the Big 10 team was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        offensive_conference="B1G"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from  Mid-American Conference (MAC) games
    # in the 2020 CFB season, where the MAC team was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        defensive_conference="MAC"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from Football Championship Subdivision (FCS) games
    # in week 3 of the 2020 CFB season,
    # where the MAC team was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        api_key=cfbd_key,
        season=2020,
        week=3,
        ncaa_division="fcs"
    )
    print(json_data)
    time.sleep(5)

    # You can also tell this function to just return the API call as
    # a Dictionary (read: JSON) object.
    print(
        "You can also tell this function to just return the API call " +
        "as a Dictionary (read: JSON) object."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        week=10,
        api_key=cfbd_key,
        return_as_dict=True
    )
    print(json_data)

else:
    # Alternatively, if the CFBD API key exists in this python environment,
    # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),
    # you could just call these functions directly,
    # without setting the API key in the script.
    print(
        "Using the user's API key supposedly loaded " +
        "into this python environment for this example."
    )

    # Get CFB Drive data from the 2020 CFB season.
    print("Get CFB Drive data from the 2020 CFB season.")
    json_data = get_cfbd_drives_info(
        season=2020
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from week 10 of the 2020 CFB season.
    print("Get CFB Drive data from week 10 of the 2020 CFB season.")
    json_data = get_cfbd_drives_info(
        season=2020,
        week=10
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats
    # Football Team.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Cincinnati Bearcats Football Team."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        team="Cincinnati"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from games involving the 2020 Ohio Bobcats
    # Football Team, when Ohio was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio Bobcats Football Team, when Ohio was on offense."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        offensive_team="Ohio"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes
    # Football Team, when Ohio was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        defensive_team="Ohio State"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from Big 12 games in the 2020 CFB season.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        conference="B12"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,
    # where the Big 10 team was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        offensive_conference="B1G"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from  Mid-American Conference (MAC) games
    # in the 2020 CFB season, where the MAC team was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        defensive_conference="MAC"
    )
    print(json_data)
    time.sleep(5)

    # Get CFB Drive data from Football Championship Subdivision (FCS) games
    # in week 3 of the 2020 CFB season,
    # where the MAC team was on offense.
    print(
        "Get CFB Drive data from games involving " +
        "the 2020 Ohio State Buckeyes Football Team, " +
        "when Ohio State was on defense."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        week=3,
        ncaa_division="fcs"
    )
    print(json_data)
    time.sleep(5)

    # You can also tell this function to just return the API call as
    # a Dictionary (read: JSON) object.
    print(
        "You can also tell this function to just return the API call " +
        "as a Dictionary (read: JSON) object."
    )
    json_data = get_cfbd_drives_info(
        season=2020,
        week=10,
        return_as_dict=True
    )
    print(json_data)

Returns

A pandas DataFrame object with CFB drive data, or (if return_as_dict is set to True) a dictionary object with CFB drive data.