Skip to content
Snippets Groups Projects
Commit 5b4e287d authored by Sukanya K's avatar Sukanya K
Browse files

first commit

parent 25187083
No related branches found
No related tags found
No related merge requests found
# # utils/payload_mapping.py
#
# def get_payload_mapping(cefr_level, scenario, scenario_question, subject, email_content):
# """
# Maps input data to the payload structure required by the API with fixed user_id, question_id, and answer_id.
#
# Args:
# cefr_level (str): The CEFR level of the input data.
# scenario (str): The scenario description.
# scenario_question (str): The scenario question.
# subject (str): The subject or topic.
# email_content (str): The email content.
#
# Returns:
# dict: The payload ready to be sent to the API.
# """
# return {
# "cefr_level": cefr_level,
# "user_id": 7600001, # Static user ID
# "question_id": 100456, # Static question ID
# "answer_id": 120000789, # Static answer ID
# "scenario": scenario,
# "scenario_question": scenario_question,
# "subject": subject,
# "email_content": email_content
# }
from config import PAYLOAD_FIELDS_STATIC
def get_payload_mapping(input_data):
"""
Maps input data to the payload structure required by the API dynamically.
Args:
input_data (dict): The dictionary containing dynamically unpacked input data.
Returns:
dict: The complete payload ready to be sent to the API.
"""
# Start with manually configured static fields from config.json
payload = PAYLOAD_FIELDS_STATIC.copy() # Ensuring we don't modify the original dictionary
# Add dynamically unpacked fields
payload.update(input_data)
return payload
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment