Issues with parsing lines from a description in Automation Studio

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)