OBJECTIVE: Develop a Python script for the Zapier Code Module to dynamically generate and output an HTML template using provided input variables. The script must be robust, handling missing or malformed data gracefully.
REQURIEMENTS: Input Variables:
- Dynamic variables provided as comma-separated strings: {Meta_Data_Artist_Name} (e.g., "Artist A,Artist B") {Meta_Data_Artist_Image_Url} (e.g., "https://example.com/a.jpg,https://example.com/b.jpg") {Meta_Data_Artist_Thank_You_Msg} (e.g., "|||Thank you for your support|||,|||We appreciate your kindness|||,|||Grateful for you|||") {Meta_Data_Artist_Slug} (e.g., "artist-a,artist-b")
- Variables are aligned by index: the first entry corresponds to the first artist, the second to the second artist, and so on. - Duplicate entries may exist where multiple products by the same artist are bought. Duplicate entries should be handled to ignore so that only unique HTML blocks for unique artists within the input strings are ajoined and output.
HTML Output:
- Generate one HTML block for each unique artist. - Join the HTML blocks into a single output for all artists. - For {Meta_Data_Artist_Thank_You_Msg}, use only the content enclosed by ||| ignoring other commas which might otherwise cause a conflict.
Name Parsing:
- Parse the artist's name from {Meta_Data_Artist_Name} as follows: - If the name contains more than one word, use only the first word. - If the name is a single word, use that word. - Capitalize the first letter of the word (e.g., "john smith" becomes "John").
Error Handling:
- If any error occurs (e.g., malformed input or missing data); - Output a fallback HTML block (attached) - Log a meaningful error message in a separate defined output. - Handle missing inputs or null values gracefully. - Trim whitespace and sanitize special characters in the input strings to avoid unintended behaviour or injection attacks.
Zapier Integration:
- Ensure output is compatible with Zapier’s requirements (e.g., JSON structure like {"html": "", "error": ""}), and output requirements. - Confirm multi-line output compatibility. - Optimised code to reduce errors, conflicts and ease of debugging.
Familiarity with Zapier preferred. Flexibility in solution allowed to meet the desired outcome. Acceptance of follow-up changes or troubleshooting is key.