Fetch Data

Makes HTTP requests given a particular WarMAC schema.
type fetch_data.T = TypeVar(T, schema.OrderResponse, schema.ItemResponse)

Invariant TypeVar constrained to schema.OrderResponse and schema.ItemResponse.

fetch_data.item_url(item: str) str

Replace spaces with underscores and ampersands with “and”.

Parameters:

item – String to manipulate.

Returns:

Manipulated string.

fetch_data.http_code_check(status_code: int) None

Check an HTTP status code and raise the appropriate WarMACHTTPError.

Check if an HTTP status code is 200 and raise the corresponding WarMACHTTPError if not.

Parameters:

status_code – HTTP status code to check.

Raises:
  • WarMACHTTPError – Raise an error from HTTP_ERROR_DICT if HTTP status code is not 200.

  • UnknownError – Raised as fallback if HTTP status code is not in HTTP_ERROR_DICT.

fetch_data.get_page(url: str, http_headers: dict[str, str]) BaseHTTPResponse

Make an HTTP request to warframe.market.

Make an HTTP request to warframe.market using the appropriate formatted URL, along with the appropriate http headers. Raise an error if the status code is not 200, otherwise, return the requested page. This page will need to be decoded into a dictionary.

Parameters:
  • url – Formatted URL used in the request.

  • http_headers – Headers to be used in the HTTP request. Must contain at least an “Accept” field.

Raises:
  • WarMACHTTPError – Raise an error from HTTP_ERROR_DICT if HTTP status code is not 200.

  • UnknownError – Raised as fallback if HTTP status code is not in HTTP_ERROR_DICT.

Returns:

Requested JSON.

fetch_data.get_data(item: str, request_schema: type[T], http_headers: dict[str, str]) T

Fetch provided item’s data from API and decode it using the schema.

Make a request to the API using the given item. Decode the raw JSON response into the WarMAC Struct associated with the provided schema.

Parameters:
  • item – Item to retrieve.

  • request_schema – Schema to use for decoding the API response. Determines the expected structure of the returned data.

  • http_headers – Headers to be used in the HTTP request.

Returns:

WarMAC Struct corresponding to the request_schema.