### Install nbainjuries and Verify Java Source: https://context7.com/mxufc29/nbainjuries/llms.txt Install the library using pip and verify that Java 8+ is correctly configured on your system's PATH. This is a prerequisite for using the library. ```bash # Requires Python 3.10+ and Java 8+ (JRE or JDK) on system PATH pip install nbainjuries # Verify Java is configured java -version ``` -------------------------------- ### Batch Retrieval - Full Season ETL Pipeline Source: https://context7.com/mxufc29/nbainjuries/llms.txt Demonstrates a complete ETL pipeline for downloading and consolidating all NBA injury reports for an entire season. It combines asynchronous validation and extraction, utilizing `check_reportvalid` and `get_reportdata` to efficiently gather data. ```APIDOC ## Batch Retrieval — Full Season ETL Pipeline Combining async validation and extraction to download and consolidate all injury report data for an entire NBA season into a single DataFrame. This is the primary pattern for large-scale data collection. ```python import asyncio from datetime import datetime, timedelta import pandas as pd from aiohttp import ClientSession from nbainjuries import injury_asy async def fetch_full_season(season_start: datetime, season_end: datetime) -> pd.DataFrame: """Fetch and consolidate all valid injury reports for a season.""" # Step 1: Generate all hourly timestamps for the season timestamps = [] ts = season_start while ts <= season_end: timestamps.append(ts) ts += timedelta(hours=1) # Step 2: Validate which timestamps have actual reports async with ClientSession() as session: validation_tasks = [ injury_asy.check_reportvalid(ts, session=session) for ts in timestamps ] valid_flags = await asyncio.gather(*validation_tasks, return_exceptions=True) valid_timestamps = [ ts for ts, flag in zip(timestamps, valid_flags) if flag is True ] print(f"Found {len(valid_timestamps)} valid reports") # Step 3: Extract all valid reports concurrently all_dfs = [] async with ClientSession() as session: extract_tasks = [ injury_asy.get_reportdata(ts, session=session, return_df=True) for ts in valid_timestamps ] results = await asyncio.gather(*extract_tasks, return_exceptions=True) for ts, df in zip(valid_timestamps, results): if isinstance(df, pd.DataFrame): df["ReportTime"] = ts.strftime("%Y-%m-%dT%H:%M") all_dfs.append(df) # Step 4: Consolidate full_season_df = pd.concat(all_dfs, ignore_index=True) print(full_season_df.shape) return full_season_df # 2024-25 regular season (excluding All-Star break Feb 14–18) df_2425 = asyncio.run( fetch_full_season( season_start=datetime(2024, 10, 21, 0, 30), season_end=datetime(2025, 4, 13, 23, 30), ) ) df_2425.to_parquet("nba_injuries_2024_25.parquet", index=False) ``` ``` -------------------------------- ### Asynchronous Batch Local Extraction Source: https://context7.com/mxufc29/nbainjuries/llms.txt Ideal for workloads involving dozens or hundreds of reports, this pattern dramatically cuts processing time through concurrency. It requires `asyncio` and is suitable for historical ETL. ```python async def batch_local(data_dir: str): timestamps = [ datetime(2024, 3, 10, 18, 0) + timedelta(hours=i) for i in range(24) ] tasks = [ injury_asy.get_reportdata(ts, local=True, localdir=data_dir, return_df=True) for ts in timestamps ] results = await asyncio.gather(*tasks, return_exceptions=True) dfs = [r for r in results if not isinstance(r, Exception)] return dfs local_dfs = asyncio.run(batch_local(DATA_DIR)) print(f"Extracted {len(local_dfs)} local reports") ``` -------------------------------- ### Local File Extraction for Injury Reports Source: https://context7.com/mxufc29/nbainjuries/llms.txt Reads NBA injury reports directly from local PDF files when `local=True` is specified. This avoids redundant network requests and requires `localdir` to be set to the directory containing the downloaded reports. ```python import asyncio from datetime import datetime, timedelta from nbainjuries import injury, injury_asy DATA_DIR = "/data/nba/injury-reports/2023-2024" ``` -------------------------------- ### Synchronous Local File Extraction Source: https://context7.com/mxufc29/nbainjuries/llms.txt Use this for ad-hoc queries and scripting when processing a single local file. Ensure the datetime object and local directory are correctly specified. ```python df = injury.get_reportdata( datetime(2024, 3, 10, 18, 0), local=True, localdir=DATA_DIR, return_df=True ) print(df[["Player Name", "Current Status", "Reason"]].head()) ``` -------------------------------- ### Local File Extraction Source: https://context7.com/mxufc29/nbainjuries/llms.txt Enables reading NBA injury reports directly from local PDF files instead of fetching them over the network. By setting `local=True` and specifying a `localdir`, the library automatically locates and reads the files based on their timestamp and the NBA's naming convention. This feature works with both synchronous and asynchronous modules. ```APIDOC ## Local File Extraction — Reading Downloaded PDFs When PDFs have already been saved locally (e.g., from a prior download run), pass `local=True` and `localdir` to avoid redundant network requests. Works with both sync and async modules; file paths are derived automatically from the timestamp using the same naming convention as the NBA's server. ```python import asyncio from datetime import datetime, timedelta from nbainjuries import injury, injury_asy DATA_DIR = "/data/nba/injury-reports/2023-2024" ``` ``` -------------------------------- ### Fetch Single Injury Report Asynchronously Source: https://context7.com/mxufc29/nbainjuries/llms.txt Fetches a single NBA injury report asynchronously. Can optionally use a shared aiohttp.ClientSession for improved performance when making many concurrent requests. ```python import asyncio from datetime import datetime from aiohttp import ClientSession from nbainjuries import injury_asy async def fetch_one(): ts = datetime(2025, 4, 25, 17, 30) # Without explicit session (auto-managed) result_json = await injury_asy.get_reportdata(ts) print(result_json[:200]) # With shared session (preferred for batch use) async with ClientSession() as session: df = await injury_asy.get_reportdata(ts, session=session, return_df=True) print(df.shape) # (N, 7) asyncio.run(fetch_one()) ``` -------------------------------- ### Generate NBA Injury Report PDF URL Source: https://context7.com/mxufc29/nbainjuries/llms.txt The `gen_url` function constructs the direct URL for an NBA injury report PDF based on the provided timestamp. It accounts for historical changes in URL formats. ```python from nbainjuries import injury from datetime import datetime url = injury.gen_url(datetime(year=2025, month=4, day=25, hour=17, minute=30)) print(url) ``` -------------------------------- ### Fetch Single Injury Report (Synchronous) Source: https://context7.com/mxufc29/nbainjuries/llms.txt Use `get_reportdata` to fetch a single NBA injury report for a specific timestamp. It can return data as a JSON string or a pandas DataFrame. For local files, set `local=True` and provide `localdir`. Custom HTTP headers can be passed using the `headers` argument. ```python from nbainjuries import injury from datetime import datetime # --- Live fetch, JSON output --- json_output = injury.get_reportdata( datetime(year=2025, month=4, day=25, hour=17, minute=30) ) print(json_output) # [ # { # "Game Date": "04/25/2025", # "Game Time": "07:00 (ET)", # "Matchup": "BOS@ORL", # "Team": "Boston Celtics", # "Player Name": "Brown, Jaylen", # "Current Status": "Questionable", # "Reason": "Injury/Illness - Right Knee; Posterior Impingement" # }, # ... # ] ``` ```python # --- Live fetch, DataFrame output --- df = injury.get_reportdata( datetime(year=2025, month=4, day=25, hour=17, minute=30), return_df=True ) print(df.head(3)) # Game Date Game Time Matchup Team Player Name Current Status Reason # 0 04/25/2025 07:00 (ET) BOS@ORL Boston Celtics Brown, Jaylen Questionable Injury/Illness - Right Knee; Posterior Impingement # 1 04/25/2025 07:00 (ET) BOS@ORL Boston Celtics Holiday, Jrue Questionable Injury/Illness - Right Hamstring; Strain # 2 04/25/2025 07:00 (ET) BOS@ORL Boston Celtics Tatum, Jayson Questionable Injury/Illness - Right Distal Radius; Bone Bruise ``` ```python # --- Local file fetch --- df_local = injury.get_reportdata( datetime(year=2024, month=3, day=10, hour=18, minute=0), local=True, localdir="/data/nba/injury-reports/2023-2024", return_df=True ) ``` ```python # --- Custom HTTP headers --- custom_headers = {"User-Agent": "MyApp/1.0", "Accept": "application/pdf"} json_custom = injury.get_reportdata( datetime(year=2025, month=1, day=15, hour=19, minute=30), headers=custom_headers ) ``` -------------------------------- ### Generate Injury Report URL Source: https://context7.com/mxufc29/nbainjuries/llms.txt Generates a formatted URL for an NBA injury report based on a given datetime object. Useful for constructing direct links to reports. ```python from datetime import datetime url_new_fmt = injury.gen_url(datetime(year=2026, month=1, day=10, hour=19, minute=15)) print(url_new_fmt) # https://ak-static.cms.nba.com/referee/injury/Injury-Report_2026-01-10_07_15PM.pdf ``` -------------------------------- ### injury.gen_url Source: https://context7.com/mxufc29/nbainjuries/llms.txt Constructs and returns the direct NBA.com URL for the injury report PDF at a given timestamp, handling historical URL format changes. ```APIDOC ## injury.gen_url — Generate Report PDF URL Constructs and returns the direct NBA.com URL for the injury report PDF at a given timestamp. Handles all historical URL format changes (legacy hourly format through December 2025, then 15-minute-increment format from December 22, 2025 onward). ### Parameters - **timestamp** (datetime) - Required - The Eastern-Time timestamp for which to generate the URL. ### Request Example ```python from nbainjuries import injury from datetime import datetime url = injury.gen_url(datetime(year=2025, month=4, day=25, hour=17, minute=30)) print(url) ``` ### Response - **URL**: A string containing the direct URL to the NBA injury report PDF. ``` -------------------------------- ### Full Season ETL Pipeline Source: https://context7.com/mxufc29/nbainjuries/llms.txt Combines asynchronous validation and extraction to download and consolidate all NBA injury report data for an entire season into a single pandas DataFrame. This is the primary pattern for large-scale data collection. ```python import asyncio from datetime import datetime, timedelta import pandas as pd from aiohttp import ClientSession from nbainjuries import injury_asy async def fetch_full_season(season_start: datetime, season_end: datetime) -> pd.DataFrame: """Fetch and consolidate all valid injury reports for a season.""" # Step 1: Generate all hourly timestamps for the season timestamps = [] ts = season_start while ts <= season_end: timestamps.append(ts) ts += timedelta(hours=1) # Step 2: Validate which timestamps have actual reports async with ClientSession() as session: validation_tasks = [ injury_asy.check_reportvalid(ts, session=session) for ts in timestamps ] valid_flags = await asyncio.gather(*validation_tasks, return_exceptions=True) valid_timestamps = [ ts for ts, flag in zip(timestamps, valid_flags) if flag is True ] print(f"Found {len(valid_timestamps)} valid reports") # Step 3: Extract all valid reports concurrently all_dfs = [] async with ClientSession() as session: extract_tasks = [ injury_asy.get_reportdata(ts, session=session, return_df=True) for ts in valid_timestamps ] results = await asyncio.gather(*extract_tasks, return_exceptions=True) for ts, df in zip(valid_timestamps, results): if isinstance(df, pd.DataFrame): df["ReportTime"] = ts.strftime("%Y-%m-%dT%H:%M") all_dfs.append(df) # Step 4: Consolidate full_season_df = pd.concat(all_dfs, ignore_index=True) print(full_season_df.shape) return full_season_df # 2024-25 regular season (excluding All-Star break Feb 14–18) df_2425 = asyncio.run( fetch_full_season( season_start=datetime(2024, 10, 21, 0, 30), season_end=datetime(2025, 4, 13, 23, 30), ) ) df_2425.to_parquet("nba_injuries_2024_25.parquet", index=False) ``` -------------------------------- ### injury_asy.get_reportdata Source: https://context7.com/mxufc29/nbainjuries/llms.txt Asynchronously fetches a single NBA injury report for a given timestamp. It can optionally accept an aiohttp.ClientSession for connection reuse. If no session is provided, a temporary one is created. The function returns the report data, and can be configured to return a pandas DataFrame. ```APIDOC ## `injury_asy.get_reportdata` — Fetch a Single Injury Report (Asynchronous) Async counterpart to `injury.get_reportdata`. Accepts an optional `aiohttp.ClientSession` for connection reuse across many concurrent requests. When `session` is `None` a temporary session is created automatically. Identical parameters and return values as the synchronous version; must be called with `await`. ```python import asyncio from datetime import datetime from aiohttp import ClientSession from nbainjuries import injury_asy async def fetch_one(): ts = datetime(2025, 4, 25, 17, 30) # Without explicit session (auto-managed) result_json = await injury_asy.get_reportdata(ts) print(result_json[:200]) # With shared session (preferred for batch use) async with ClientSession() as session: df = await injury_asy.get_reportdata(ts, session=session, return_df=True) print(df.shape) # (N, 7) asyncio.run(fetch_one()) ``` ``` -------------------------------- ### Retrieve Batch Injury Reports (Asynchronous) Source: https://github.com/mxufc29/nbainjuries/blob/main/README.md Retrieves and consolidates injury report data for a specified period or a random sample using asynchronous processing for improved speed. ```APIDOC ## Batch Report Query ### Description Retrieves and consolidates injury report data for a specified period or a random sample using asynchronous processing for improved speed. This method utilizes the `injury_asy` module and `asyncio` for concurrent processing. ### Method `injury_asy.get_reportdata_batch(...)` (Details on parameters for batch processing, season, or random sampling are not explicitly provided in the source text, but the module `injury_asy` and `asyncio` are indicated for this purpose.) ### Parameters (Specific parameters for batch queries, season selection, or random sampling are not detailed in the provided source text. Refer to the library's implementation for exact usage.) ### Request Example ```python # Example demonstrating the concept, actual implementation may vary import asyncio from nbainjuries import injury_asy async def fetch_batch_reports(): # Placeholder for actual batch fetching logic # This would involve calling injury_asy.get_reportdata_batch with appropriate arguments # For example, to fetch all reports for the 2023-2024 season: # reports = await injury_asy.get_reportdata_batch(season='2023-2024') # Or for a random sample: # reports = await injury_asy.get_reportdata_batch(sample_size=100, season='2023-2024') pass # asyncio.run(fetch_batch_reports()) ``` ### Response (The structure of the consolidated batch response is not explicitly defined in the source text. It is expected to be a collection of injury records, potentially in JSON or DataFrame format, similar to the single report query but aggregated.) ``` -------------------------------- ### Validate Report Availability Asynchronously Source: https://context7.com/mxufc29/nbainjuries/llms.txt Asynchronously checks if an NBA injury report is available for a given timestamp. Designed for concurrent validation of many timestamps using asyncio.gather. ```python import asyncio from datetime import datetime, timedelta from aiohttp import ClientSession from nbainjuries import injury_asy async def validate_range(): start = datetime(2025, 4, 20, 0, 30) timestamps = [start + timedelta(hours=i) for i in range(72)] # 3 days async with ClientSession() as session: tasks = [ injury_asy.check_reportvalid(ts, session=session) for ts in timestamps ] results = await asyncio.gather(*tasks) valid = [ts for ts, ok in zip(timestamps, results) if ok] print(f"{len(valid)} valid reports found out of {len(timestamps)} checked") return valid valid_timestamps = asyncio.run(validate_range()) ``` -------------------------------- ### Query Single Injury Report in JSON and DataFrame Source: https://github.com/mxufc29/nbainjuries/blob/main/README.md Retrieve injury report data for a specific date and time. Supports both JSON and DataFrame return formats. Ensure the datetime object is correctly formatted. ```python from nbainjuries import injury from datetime import datetime json_output = injury.get_reportdata(datetime(year=2025, month=4, day=25, hour=17, minute=30)) df_output = injury.get_reportdata(datetime(year=2025, month=4, day=25, hour=17, minute=30), return_df=True) ``` ```json [ { "Game Date":"04\/25\/2025", "Game Time":"07:00 (ET)", "Matchup":"BOS@ORL", "Team":"Boston Celtics", "Player Name":"Brown, Jaylen", "Current Status":"Questionable", "Reason":"Injury\/Illness - Right Knee; Posterior Impingement" }, { "Game Date":"04\/25\/2025", "Game Time":"07:00 (ET)", "Matchup":"BOS@ORL", "Team":"Boston Celtics", "Player Name":"Holiday, Jrue", "Current Status":"Questionable", "Reason":"Injury\/Illness - Right Hamstring; Strain" }, { "Game Date":"04\/25\/2025", "Game Time":"07:00 (ET)", "Matchup":"BOS@ORL", "Team":"Boston Celtics", "Player Name":"Tatum, Jayson", "Current Status":"Questionable", "Reason":"Injury\/Illness - Right Distal Radius; Bone Bruise" }, { "Game Date":"04\/25\/2025", "Game Time":"07:00 (ET)", "Matchup":"BOS@ORL", "Team":"Orlando Magic", "Player Name":"Suggs, Jalen", "Current Status":"Out", "Reason":"Injury\/Illness - Left Knee; Trochlea cartilage tear" }, ... ] ``` -------------------------------- ### injury.get_reportdata Source: https://context7.com/mxufc29/nbainjuries/llms.txt Fetches a single NBA player injury report for a given Eastern-Time timestamp. Supports returning data as JSON or a pandas DataFrame, and can read from local files. ```APIDOC ## injury.get_reportdata — Fetch a Single Injury Report (Synchronous) Extracts all player injury records from the official NBA injury report PDF at the given Eastern-Time timestamp. Returns a JSON string by default, or a pandas DataFrame when `return_df=True`. Reports are published approximately every 30–60 minutes on game days; pass the exact timestamp shown on the report (rounded to the nearest 30-minute increment). Use `local=True` with `localdir` to read a previously downloaded PDF instead of fetching from the network. ### Parameters - **timestamp** (datetime) - Required - The Eastern-Time timestamp for the report. - **return_df** (bool) - Optional - If True, returns a pandas DataFrame; otherwise, returns a JSON string. Defaults to False. - **local** (bool) - Optional - If True, reads the report from a local file instead of fetching from the network. Defaults to False. - **localdir** (str) - Optional - The directory containing the local PDF report when `local=True`. - **headers** (dict) - Optional - Custom HTTP headers to use for the network request. ### Request Example ```python from nbainjuries import injury from datetime import datetime # Live fetch, JSON output json_output = injury.get_reportdata( datetime(year=2025, month=4, day=25, hour=17, minute=30) ) print(json_output) # Live fetch, DataFrame output df = injury.get_reportdata( datetime(year=2025, month=4, day=25, hour=17, minute=30), return_df=True ) print(df.head(3)) # Local file fetch df_local = injury.get_reportdata( datetime(year=2024, month=3, day=10, hour=18, minute=0), local=True, localdir="/data/nba/injury-reports/2023-2024", return_df=True ) # Custom HTTP headers custom_headers = {"User-Agent": "MyApp/1.0", "Accept": "application/pdf"} json_custom = injury.get_reportdata( datetime(year=2025, month=1, day=15, hour=19, minute=30), headers=custom_headers ) ``` ### Response #### Success Response - **JSON Output**: A JSON string representing a list of player injury records. - **DataFrame Output**: A pandas DataFrame with columns like 'Game Date', 'Game Time', 'Matchup', 'Team', 'Player Name', 'Current Status', 'Reason'. ``` -------------------------------- ### Retrieve Single Injury Report Source: https://github.com/mxufc29/nbainjuries/blob/main/README.md Fetches the injury report data for a specific date and time. Supports both JSON and DataFrame output formats. ```APIDOC ## Retrieve Single Injury Report ### Description Fetches the injury report data for a specific date and time. Supports both JSON and DataFrame output formats. ### Method `injury.get_reportdata(datetime_obj, return_df=False)` ### Parameters #### Path Parameters None #### Query Parameters - **datetime_obj** (datetime) - Required - The specific date and time for which to retrieve the report. - **return_df** (bool) - Optional - If True, returns the data as a pandas DataFrame. Defaults to False (returns JSON). ### Request Example ```python from nbainjuries import injury from datetime import datetime # Get report as JSON json_output = injury.get_reportdata(datetime(year=2025, month=4, day=25, hour=17, minute=30)) # Get report as DataFrame df_output = injury.get_reportdata(datetime(year=2025, month=4, day=25, hour=17, minute=30), return_df=True) ``` ### Response #### Success Response (JSON) - **Game Date** (string) - The date of the game. - **Game Time** (string) - The time of the game (ET). - **Matchup** (string) - The matchup string (e.g., BOS@ORL). - **Team** (string) - The team name. - **Player Name** (string) - The name of the player. - **Current Status** (string) - The player's current status (e.g., Questionable, Out, Available). - **Reason** (string) - The reason for the player's status. #### Success Response (DataFrame) A pandas DataFrame with columns corresponding to the JSON fields. ### Response Example (JSON) ```json [ { "Game Date":"04\/25\/2025", "Game Time":"07:00 (ET)", "Matchup":"BOS@ORL", "Team":"Boston Celtics", "Player Name":"Brown, Jaylen", "Current Status":"Questionable", "Reason":"Injury\/Illness - Right Knee; Posterior Impingement" } ] ``` ``` -------------------------------- ### Validate Report Availability (Synchronous) Source: https://context7.com/mxufc29/nbainjuries/llms.txt Use `check_reportvalid` to determine if an NBA injury report PDF exists for a given timestamp without downloading the file. It returns `True` if the report is accessible and `False` otherwise, including network errors or non-existent reports. ```python from nbainjuries import injury from datetime import datetime # Check a known game-day timestamp is_valid = injury.check_reportvalid( datetime(year=2025, month=4, day=25, hour=17, minute=30) ) print(is_valid) # True # Check an offseason / All-Star break timestamp — no report exists is_valid_offseason = injury.check_reportvalid( datetime(year=2025, month=2, day=16, hour=12, minute=0) ) print(is_valid_offseason) # False # Iterate over a range and filter for valid timestamps from datetime import timedelta start = datetime(2025, 4, 20, 0, 30) valid_timestamps = [] for i in range(48): # check 48 hourly slots (~2 days) ts = start + timedelta(hours=i) if injury.check_reportvalid(ts): valid_timestamps.append(ts) print(f"Found {len(valid_timestamps)} valid reports") ``` -------------------------------- ### get_reportdata (Synchronous) Source: https://github.com/mxufc29/nbainjuries/blob/main/Documentation.md Extracts the injury data from the injury report at a specific datetime. ```APIDOC ## get_reportdata(timestamp: datetime, local: bool = False, localdir: str | PathLike = None, return_df: bool = False, **kwargs) ### Description Extracts the injury data from the injury report at a specific datetime. ### Parameters - **timestamp** (datetime) - Required - date/time of the report for retrieval in `datetime` form (all times ET). Reports are generally timestamped hourly, at 30 minute increments of the hour. - E.g. `datetime(year=2023, month=5, day=2, hour=17, minute=30)`for report at 5/2/2023 5:30pm ET - **local** (bool) - Optional - if the source file from which to extract is saved on local drive; default `False` (live retrieve from URL) - **localdir** (str | PathLike) - Optional - local directory path of data source, required if `local=True` - **return_df** (bool) - Optional - return output data as dataframe, default `False` (return as json) - **kwargs** - Optional - any custom HTML headers to override default headers for HTML request ``` -------------------------------- ### get_reportdata (Asynchronous) Source: https://github.com/mxufc29/nbainjuries/blob/main/Documentation.md Extracts the injury data from the injury report at a specific datetime using asynchronous operations. ```APIDOC ## get_reportdata(timestamp: datetime, session: ClientSession = None, local: bool = False, localdir: str | PathLike = None, return_df: bool = False, **kwargs) ### Description Extracts the injury data from the injury report at a specific datetime. This is the asynchronous version compatible with `asyncio`. ### Parameters - **timestamp** (datetime) - Required - date/time of the report for retrieval in `datetime` form (all times ET). - **session** (ClientSession) - Optional - session for managing concurrent requests. - **local** (bool) - Optional - if the source file from which to extract is saved on local drive; default `False`. - **localdir** (str | PathLike) - Optional - local directory path of data source, required if `local=True`. - **return_df** (bool) - Optional - return output data as dataframe, default `False` (return as json). - **kwargs** - Optional - any custom HTML headers to override default headers for HTML request. ``` -------------------------------- ### check_reportvalid (Synchronous) Source: https://github.com/mxufc29/nbainjuries/blob/main/Documentation.md Check the data availability of the injury report (url) at a specific datetime. ```APIDOC ## check_reportvalid(timestamp: datetime, **kwargs) -> bool ### Description Check the data availability of the injury report (url) at a specific datetime. ### Parameters - **timestamp** (datetime) - Required - date and time of the report, in `datetime` form - **kwargs** - Optional - any user-specified HTML headers to override default headers for the HTML request ``` -------------------------------- ### check_reportvalid (Asynchronous) Source: https://github.com/mxufc29/nbainjuries/blob/main/Documentation.md Check the data availability of the injury report (url) at a specific datetime using asynchronous operations. ```APIDOC ## check_reportvalid(timestamp: datetime, session: ClientSession = None, **kwargs)-> bool ### Description Check the data availability of the injury report (url) at a specific datetime using asynchronous operations. ### Parameters - **timestamp** (datetime) - Required - date and time of the report, in `datetime` form. - **session** (ClientSession) - Optional - session for managing concurrent requests. - **kwargs** - Optional - any user-specified HTML headers to override default headers for the HTML request. ``` -------------------------------- ### injury_asy.check_reportvalid Source: https://context7.com/mxufc29/nbainjuries/llms.txt Asynchronously checks if an NBA injury report is available for a given timestamp. It accepts an optional aiohttp.ClientSession and returns a coroutine that resolves to a boolean indicating availability. This function is designed for efficient concurrent validation of multiple timestamps. ```APIDOC ## `injury_asy.check_reportvalid` — Validate Report Availability (Asynchronous) Async counterpart to `injury.check_reportvalid`. Accepts an optional `ClientSession`. Returns a coroutine that resolves to `True` or `False`. Designed for concurrent URL validation over large date ranges using `asyncio.gather`. ```python import asyncio from datetime import datetime, timedelta from aiohttp import ClientSession from nbainjuries import injury_asy async def validate_range(): start = datetime(2025, 4, 20, 0, 30) timestamps = [start + timedelta(hours=i) for i in range(72)] # 3 days async with ClientSession() as session: tasks = [ injury_asy.check_reportvalid(ts, session=session) for ts in timestamps ] results = await asyncio.gather(*tasks) valid = [ts for ts, ok in zip(timestamps, results) if ok] print(f"{len(valid)} valid reports found out of {len(timestamps)} checked") return valid valid_timestamps = asyncio.run(validate_range()) ``` ``` -------------------------------- ### injury.check_reportvalid Source: https://context7.com/mxufc29/nbainjuries/llms.txt Checks if a valid NBA injury report PDF exists on the NBA's server for a specified timestamp without downloading the entire file. Returns True if the report is accessible, False otherwise. ```APIDOC ## injury.check_reportvalid — Validate Report Availability (Synchronous) Checks whether a valid injury report PDF exists at the NBA's server for the specified timestamp without downloading or parsing the full PDF. Returns `True` if the report is accessible, `False` otherwise (including network errors or reports that do not exist for that timestamp, such as during the All-Star break or offseason). ### Parameters - **timestamp** (datetime) - Required - The Eastern-Time timestamp to check for a report. ### Request Example ```python from nbainjuries import injury from datetime import datetime # Check a known game-day timestamp is_valid = injury.check_reportvalid( datetime(year=2025, month=4, day=25, hour=17, minute=30) ) print(is_valid) # True # Check an offseason / All-Star break timestamp — no report exists is_valid_offseason = injury.check_reportvalid( datetime(year=2025, month=2, day=16, hour=12, minute=0) ) print(is_valid_offseason) # False # Iterate over a range and filter for valid timestamps from datetime import timedelta start = datetime(2025, 4, 20, 0, 30) valid_timestamps = [] for i in range(48): # check 48 hourly slots (~2 days) ts = start + timedelta(hours=i) if injury.check_reportvalid(ts): valid_timestamps.append(ts) print(f"Found {len(valid_timestamps)} valid reports") ``` ### Response - **Boolean**: `True` if a report exists for the timestamp, `False` otherwise. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.