cheesechaser.query.base

This module provides a base class for web querying operations.

It includes functionality for filtering items, managing sessions, and iterating over query results. The module is designed to be extended for specific web querying tasks.

Key features:

  • Flexible session management (supports both httpx.Client and requests.Session)

  • Customizable item filtering

  • Rate limiting for API requests

  • Progress bar display during iteration

Classes:

  • BaseWebQuery: A base class for creating web query objects with filtering capabilities.

Usage:

This module is not intended to be used directly, but rather to be subclassed for specific web querying implementations. Subclasses should implement the following methods:

  • _get_session()

  • _iter_items()

  • _get_length()

BaseWebQuery

class cheesechaser.query.base.BaseWebQuery(filters: List[Callable[[Any], bool]] | None = None)[source]

A base class for web querying operations.

This class provides a foundation for creating web query objects with filtering capabilities. It manages sessions (either httpx.Client or requests.Session) and provides methods for iterating over query results with optional filtering.

Attributes:

__api_rate_limit__ (int): The number of API requests allowed per interval. __api_rate_interval__ (float): The time interval (in seconds) for rate limiting.

Parameters:

filters (Optional[List[_ItemFilterTyping]]) – A list of callable filter functions to apply to query results.

__init__(filters: List[Callable[[Any], bool]] | None = None)[source]

Initialize the BaseWebQuery object.

Parameters:

filters (Optional[List[_ItemFilterTyping]]) – A list of callable filter functions to apply to query results.

__iter__() Iterator[int][source]

Iterate over filtered query result IDs.

This method yields unique IDs of items that pass all filters. It uses tqdm to display a progress bar during iteration.

Returns:

An iterator of unique item IDs that pass all filters.

Return type:

Iterator[int]

__weakref__

list of weak references to the object (if defined)

property session: Client | Session

Get the session object, creating it if it doesn’t exist.

This property ensures that a session object is always available for making HTTP requests.

Returns:

The session object for making HTTP requests.

Return type:

Union[httpx.Client, requests.Session]