Issues with parsing lines from a description in Automation Studio

I’m having a problem with Automation Studio in Parsing data from a multi-line text field. I want each line in a separate variable and I’ve tried Python and Ruby to do this but the examples and sample codes just don’t seem to be complete enough. I’m able to get the data into the code but unable to get it to export the code into the variables that I have setup:

image

Is anyone experienced with this type of setup that can point me in the right direction?

Create array from your output and then update each variable with myarray[0], myarray[1]

We did find a way to do it, this is what we came up with:

from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
def init(self):
super().init()
self.variables = {}
self.current_data = “”
self.counter = 0

def handle_starttag(self, tag, attrs):
    for attr in attrs:
        if attr[0] == 'class' and attr[1] == 'MsoNormal':
            self.counter += 1

def handle_data(self, data):
    if data.strip() and self.counter > 0:
        self.current_data += data.strip()
        self.variables[f'var_{self.counter}'] = self.current_data

def handle_endtag(self, tag):
    if tag == 'div':
        self.current_data = ""

def split_text_to_variables(multi_line_text):
lines = multi_line_text.split(‘\n’)
variables = {}
for i, line in enumerate(lines):
variable_name = f’var_{i+1}’
variables[variable_name] = line
return variables

def main(input):
# Access the values of the action’s Input fields
body = input[‘Body’]

# Split the text to variables
text_variables = split_text_to_variables(body)

# Create a parser instance
parser = MyHTMLParser()

# Feed the HTML content to the parser
parser.feed(body)

# Combine both sets of variables
combined_variables = {**text_variables, **parser.variables}
return combined_variables

Example input

input_data = {
‘Body’: “

First line of text
\nSecond line of text\n
Third line of text

}

Run the main function

output = main(input_data)