class splatnet3_scraper.query.QueryResponse

The QueryResponse class represents a response from the SplatNet 3 API. The class provides various convenience methods for interacting with the returned data and contains metadata about the response. The metadata contains the query that was used to get the data and the timestamp of the response. Additional metadata may be added in the future. Using the getitem method on the response will return another QueryResponse with the data from the key. If the data is a list, the getitem method will generate a QueryResponse for each item in the list. The QueryResponse class also provides a parse_json method that returns a JSONParser object for the response data. This is currently not used by the library, so it may be removed in the future.

Constructors

QueryResponse(data, metadata=None)

Initializes a QueryResponse.

Special methods

__eq__(other)

Returns whether the QueryResponse is equal to another object.

__getitem__(key)

Returns a QueryResponse object containing the data at the given key. If the key is a tuple, this method will treat it as taking multiple keys in order to get to the data. For example, the following two are equivalent:

__iter__()

Returns an iterator over the values in the data.

String representation

__repr__()

Returns a string representation of the QueryResponse.

Methods

apply(func, key, partial=True)

Applies a function to the data.

apply_reduce(func, reduce_func, key, partial=True)

Applies a function to the data and then reduces the result.

get(key, default=None)

Returns the value at the given key. If the key is not found, returns the default value.

get_partial_path(partial_path, *args, unpack_query_response=True)

Returns a list of values for all paths in the given data that match the provided partial path. This function first calls match_partial_path to find all matching paths and then retrieves the value at each of those paths using the get method.

items()

Returns a list of items in the data. If the top level of the data is a list, this method will return a list of integers from 0 to the length as the keys.

keys()

Returns a list of keys in the data. If the top level of the data is a list, this method will return a list of integers from 0 to the length of the list.

match_partial_path(partial_path, *args)

Returns a list of all paths in the given data that match the given partial path. For example, if partial_path is (0, "key1"), this will return all paths in the data that match ...[0]["key1"]. If fed a list of partial paths, this will return all paths that match any of the partial paths. Do not confuse tuples with lists, as they are treated differently.

parse_json()

The JSONParser object containing the data.

show(return_value: False) None
show(return_value: True) dict[str, Any]

Prints the data to the console. If return_value is True, returns the data as a dict instead.

to_gzipped_json(path)

Saves the data to a gzipped JSON file.

to_json(path)

Saves the data to a JSON file.

values()

Returns a list of values in the data.

Properties

property data : dict[str, Any] | list[dict[str, Any]]

The raw data from the response. This is the data that was passed to the QueryResponse at initialization.

property metadata : MetaData

The metadata from the response.

property query : str

The query that was used to get the data.

property timestamp : datetime

The timestamp of the response, as a datetime object.

property timestamp_raw : float

The timestamp of the response, as a float.