App/Model.py
def clean_description(self, soup, elem, clean):
        # TODO: remove after implement the Topic() class
        """
        Clean the page's description from the beatifulSoup object

        Args:
            soup (bs-obj): beatifulSoup object with the description data
            elem (str): HTML <div> keyword to scrap the description data
            clean (list): secondary <div> to clean the description data

        Raises:
            exp: raise a generic exception if something goes wrong

        Returns:
            ans (dict): Element (paint) clean description
        """
        try:
            # get the title in the painting page
            ans = dict()

            # some pages dont follow the most commond diagram
            if soup is not None:

                if len(soup) > 0:

                    # finding title <h1> in the soup
                    value = soup[0].find(elem[0])
                    # cleaning data
                    key = value.attrs.get(clean[0])[0]
                    key = str(key).replace(clean[1], "", 1)
                    key = self.clrtext(key)

                    value = str(value.string).strip()
                    value = self.clrtext(value)

                    # creating the dict to return to save as JSON
                    td = {key: value}
                    # updating answer dict
                    ans.update(copy.deepcopy(td))

                    # finding all description paragraphs <p> in the soup
                    description = soup[0].findAll(elem[1])
                    for element in description:

                        key = element.attrs.get(clean[0])[0]
                        key = str(key)
                        key = key.replace(clean[1], "", 1)
                        key = self.clrtext(key)

                        value = str(element.string).strip()
                        value = self.clrtext(value)

                        # creating the dict to return to save as JSON
                        td = {key: value}

                        # updating answer dict
                        ans.update(copy.deepcopy(td))

                    # getting description text section
                    key = soup[1]
                    key = key.attrs.get(clean[0])[0]
                    key = str(key)
                    key = key.replace(clean[1], "", 1)
                    key = self.clrtext(key)

                    # getting section description text
                    text = soup[1].find(elem[1])
                    value = str()
                    for txt in text:
                        txt = txt.string
                        txt = str(txt)
                        value = value + txt

                    # cleaning data
                    value = str(value).strip()
                    value = self.clrtext(value)

                    # updating answer dict
                    td = {key: value}
                    ans.update(copy.deepcopy(td))

                    # finding all the related links in the description
                    links = soup[1].findAll(elem[2])
                    for link in links:
                        key = str(link.string)
                        key = self.clrtext(key)

                        # getting the link URL
                        value = link.get(clean[2])
                        # reconstructing all the url from the page
                        value = str(value)
                        td = {key: value}

                        # creating the dict to return to save as JSON
                        td = {key: value}

                        # updating answer dict
                        ans.update(copy.deepcopy(td))

            # returning answer
            return ans

        # exception handling
        except Exception as exp:
            Err.reraise(exp, "Gallery: clean_description")

        Clean the page's description from the beatifulSoup object

        Args:
            soup (bs-obj): beatifulSoup object with the description data
            elem (str): HTML <div> keyword to scrap the description data
            clean (list): secondary <div> to clean the description data

        Raises:
            exp: raise a generic exception if something goes wrong

        Returns:
            ans (dict): Element (paint) clean description
        
Clean the page's description from the beatifulSoup object
Clean the page ' s description from the beatifulSoup object
def clean_description(self, soup, elem, clean):
        try:
            ans = dict()
            if soup is not None:
                if len(soup) > 0:
                    value = soup[0].find(elem[0])
                    key = value.attrs.get(clean[0])[0]
                    key = str(key).replace(clean[1], "", 1)
                    key = self.clrtext(key)
                    value = str(value.string).strip()
                    value = self.clrtext(value)
                    td = {key: value}
                    ans.update(copy.deepcopy(td))
                    description = soup[0].findAll(elem[1])
                    for element in description:
                        key = element.attrs.get(clean[0])[0]
                        key = str(key)
                        key = key.replace(clean[1], "", 1)
                        key = self.clrtext(key)
                        value = str(element.string).strip()
                        value = self.clrtext(value)
                        td = {key: value}
                        ans.update(copy.deepcopy(td))
                    key = soup[1]
                    key = key.attrs.get(clean[0])[0]
                    key = str(key)
                    key = key.replace(clean[1], "", 1)
                    key = self.clrtext(key)
                    text = soup[1].find(elem[1])
                    value = str()
                    for txt in text:
                        txt = txt.string
                        txt = str(txt)
                        value = value + txt
                    value = str(value).strip()
                    value = self.clrtext(value)
                    td = {key: value}
                    ans.update(copy.deepcopy(td))
                    links = soup[1].findAll(elem[2])
                    for link in links:
                        key = str(link.string)
                        key = self.clrtext(key)
                        value = link.get(clean[2])
                        value = str(value)
                        td = {key: value}
                        td = {key: value}
                        ans.update(copy.deepcopy(td))
            return ans
        except Exception as exp:
            Err.reraise(exp, "Gallery: clean_description")
def clean_description ( self , soup , elem , clean ) : try : ans = dict ( ) if soup is not None : if len ( soup ) > 0 : value = soup [ 0 ] . find ( elem [ 0 ] ) key = value . attrs . get ( clean [ 0 ] ) [ 0 ] key = str ( key ) . replace ( clean [ 1 ] , "" , 1 ) key = self . clrtext ( key ) value = str ( value . string ) . strip ( ) value = self . clrtext ( value ) td = { key : value } ans . update ( copy . deepcopy ( td ) ) description = soup [ 0 ] . findAll ( elem [ 1 ] ) for element in description : key = element . attrs . get ( clean [ 0 ] ) [ 0 ] key = str ( key ) key = key . replace ( clean [ 1 ] , "" , 1 ) key = self . clrtext ( key ) value = str ( element . string ) . strip ( ) value = self . clrtext ( value ) td = { key : value } ans . update ( copy . deepcopy ( td ) ) key = soup [ 1 ] key = key . attrs . get ( clean [ 0 ] ) [ 0 ] key = str ( key ) key = key . replace ( clean [ 1 ] , "" , 1 ) key = self . clrtext ( key ) text = soup [ 1 ] . find ( elem [ 1 ] ) value = str ( ) for txt in text : txt = txt . string txt = str ( txt ) value = value + txt value = str ( value ) . strip ( ) value = self . clrtext ( value ) td = { key : value } ans . update ( copy . deepcopy ( td ) ) links = soup [ 1 ] . findAll ( elem [ 2 ] ) for link in links : key = str ( link . string ) key = self . clrtext ( key ) value = link . get ( clean [ 2 ] ) value = str ( value ) td = { key : value } td = { key : value } ans . update ( copy . deepcopy ( td ) ) return ans except Exception as exp : Err . reraise ( exp , "Gallery: clean_description" )
Clean the page's description from the beatifulSoup object
Clean the page ' s description from the beatifulSoup object
# TODO: remove after implement the Topic() class """
        Clean the page's description from the beatifulSoup object

        Args:
            soup (bs-obj): beatifulSoup object with the description data
            elem (str): HTML <div> keyword to scrap the description data
            clean (list): secondary <div> to clean the description data

        Raises:
            exp: raise a generic exception if something goes wrong

        Returns:
            ans (dict): Element (paint) clean description
        """ # get the title in the painting page # some pages dont follow the most commond diagram # finding title <h1> in the soup # cleaning data # creating the dict to return to save as JSON # updating answer dict # finding all description paragraphs <p> in the soup # creating the dict to return to save as JSON # updating answer dict # getting description text section # getting section description text # cleaning data # updating answer dict # finding all the related links in the description # getting the link URL # reconstructing all the url from the page # creating the dict to return to save as JSON # updating answer dict # returning answer # exception handling
ans (dict): Element (paint) clean description
ans ( dict ) : Element ( paint ) clean description
raise a generic exception if something goes wrong
raise a generic exception if something goes wrong
exp
self
soup
beatifulSoup object with the description data
beatifulSoup object with the description data
elem
HTML  keyword to scrap the description data
HTML keyword to scrap the description data
clean
secondary  to clean the description data
secondary to clean the description data