Select Git revision
test_excel_operation.cpython-310-pytest-8.3.5.pyc
unpack_data.py 924 B
from config import INPUT_FIELDS_DYNAMIC
from utils.payload_mapping import get_payload_mapping
def unpack_input_data(input_data):
"""
Unpacks input data dynamically using JSON-defined mappings.
Args:
input_data (dict): The dictionary containing raw input data (e.g., from Excel).
Returns:
dict or None: The prepared payload for the API request or None if the row is empty.
"""
unpacked_data = {}
# Loop through INPUT_FIELDS mapping from config.json to dynamically unpack data
for excel_field, payload_key in INPUT_FIELDS_DYNAMIC.items():
unpacked_data[payload_key] = input_data.get(excel_field, "").strip() # Strip whitespace
# Check if all unpacked values are empty
if all(value == "" for value in unpacked_data.values()):
return None # Skip empty rows
# Pass valid data to get_payload_mapping
return get_payload_mapping(unpacked_data)