ActoKids / AD440_W19_CloudPracticum

3 stars 1 forks source link

Validating OFA Description for URL's #115

Closed MikeJLeon closed 5 years ago

MikeJLeon commented 5 years ago

After getting feedback from Erik, I would like you to help me with my code to just check the description data and ensure if any links are present in the data then to add or retain the anchor tags so that they appear properly in the UI

MikeJLeon commented 5 years ago

Good work @daonguyen81 it add the anchors as expected now.

daonguyen81 commented 5 years ago

Time spent: 2 hrs. Anchor tag added

url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+] |[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', row.text)
                    if url:
                        for word in row.text.split():
                            if 'http' in word:
                                link_url = '<a href="{}"'.format(word) + ' target="{}"><strong>'.format('_blank') + word + '</strong></a>'
                                p_desc = p_desc + link_url + " "
                            else:
                                p_desc = p_desc + word + " "

                    else: 
                        p_desc = p_desc + row.text                             
                        if row.findAll("a"):
                            for link in row.findAll("a"):
                                if link.has_attr('href'):
                                    link_url = '<a href="{}"'.format(link['href']) + ' target="{}"><strong>'.format('_blank') + link.text + '</strong></a>'
                                    if link.text in p_desc:
                                        p_desc = p_desc.replace(link.text, link_url)