caoscrawler.transformers.cast_and_parse_transformers module#
Transformer functions for casting and parsing.
See https://docs.linkahead.org/ for more information.
- caoscrawler.transformers.cast_and_parse_transformers.cast_to_bool(in_value: Any, params: dict) bool#
Cast a given value to bool. This is done by comparing it against “true” and “false”, case-insensitive. Any input values not matching either raise an error.
- Parameters:
in_value (Any) – Value to be cast to bool.
params (dict) – No parameters are expected.
- Returns:
result – The input value cast to bool.
- Return type:
bool
- Raises:
ValueError – If input value is an invalid value for type cast to bool.
- caoscrawler.transformers.cast_and_parse_transformers.cast_to_float(in_value: Any, params: dict) float#
Cast a given value to float.
- Parameters:
in_value (Any) – Value to be cast to float.
params (dict) – No parameters are expected.
- Returns:
result – The input value cast to float.
- Return type:
float
- caoscrawler.transformers.cast_and_parse_transformers.cast_to_int(in_value: Any, params: dict) int#
Cast a given value to int.
- Parameters:
in_value (Any) – Value to be cast to integer.
params (dict) – No parameters are expected.
- Returns:
result – The input value cast to int.
- Return type:
int
- caoscrawler.transformers.cast_and_parse_transformers.cast_to_str(in_value: Any, params: dict) str#
Cast a given value to string.
- Parameters:
in_value (Any) – Value to be cast to string.
params (dict) – No parameters are expected.
- Returns:
result – The input value cast to string.
- Return type:
string
- caoscrawler.transformers.cast_and_parse_transformers.date_parse(in_value: str, params: dict) str#
Transform a string containing a date to the format expected by LinkAhead.
- Parameters:
in_value (str) – String containing the date to format.
params (dict) –
- “date_format”: optional.
The
datetimeformat of the original date, see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes Alternative keys: “format”, “format_str”, “old_format”
- Returns:
date – Formatted date.
- Return type:
str
- caoscrawler.transformers.cast_and_parse_transformers.datetime_parse(in_value: str, params: dict) str#
Transform a string containing a date and time to the format expected by LinkAhead.
- Parameters:
in_value (str) – String containing the datetime to format.
params (dict) –
- “datetime_format”: optional.
The
datetimeformat of the original datetime, see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes Alternative keys: “format”, “format_str”, “old_format”
- Returns:
date – Formatted datetime.
- Return type:
str
- caoscrawler.transformers.cast_and_parse_transformers.force_to_bool(in_value: Any, params: dict) bool#
Cast a given value to bool, by using their Python __bool__ function.
- Parameters:
in_value (Any) – Value to be cast to bool.
params (dict) – No parameters are expected.
- Returns:
result – The input value cast to bool.
- Return type:
bool