I am trying to add multiple rows of data into an excel file using zapier from a single slack message. However, I am able to pull only one row at the moment.
Below is the slack message format that I am using. It can have multiple client to description sets which represent each row of data needed in excel file.
Client: ABC
Platform (MP/IX/UP): IX
Handover Type (Proactive/Reactive/Tracker): Proactive
Project ID: 1234567
Status (SL/FL/Paused/Waiting): FL
RL: N/A
Description: This is a description text.
Description text can have multiple paragraphs.
Client: XYZ
Platform (MP/IX/UP): IX
Handover Type (Proactive/Reactive/Tracker): Reactive
Project ID: 12345678
Status (SL/FL/Paused/Waiting): FL
RL: N/A
Description: This is also a description text.
Description text can have multiple paragraphs.
There is also a caveat that the description text may also have multiple lines or paragraphs, which means it can have new line characters.
I tried using code by zapier to run the following python script to format the message, but the issue is it pulls only 1 row of data to excel.
# Get the message from the input data
message = input_data["Message"]
# Split the message into lines
lines = message.split("\n")
# Initialize an empty dictionary to store the data
data = {}
# Loop through each line in the lines list
for line in lines:
# Ignore blank lines
if line.strip() == "":
continue
# Split the line into key and value at the first occurrence of ":"
key, value = line.split(":", 1)
# Strip any leading or trailing spaces from the key and value
key = key.strip()
value = value.strip()
# Check if the key is "Description"
if key == "Description":
# If the key is "Description", check if there is already a value
if "Description" in data:
# If there is already a value, append the current line to the existing value
data["Description"] += "\n" + value
else:
# If there is no existing value, set the current line as the value
data["Description"] = value
else:
# Add the key-value pair to the data dictionary
data[key] = value
# Initialize an empty list to store the output
output = []
# Append the data dictionary to the output list
output.append(data)
If anyone can help me in directing me to how can we achieve this. Please note I am not into coding, though I know a little bit of it.
You are not correctly appending
dataintooutputlist. Your code structure should go something like this:This way you'll append data to output in each iteration thereby getting data for each data point.