perceval/backends/core/askbot.py
def parse_user_info(update_info):
        """Parse the user information of a given HTML container.

        The method parses all the available user information in the container.
        If the class "user-info" exists, the method will get all the available
        information in the container. If not, if a class "tip" exists, it will be
        a wiki post with no user associated. Else, it can be an empty container.

        :param update_info: beautiful soup answer container element

        :returns: an object with the parsed information
        """
        user_info = {}
        if update_info.select("div.user-info"):
            # Get all the <a> elements in the container. First <a> contains the user
            # information, second one (if exists), the website of the user.
            elements = update_info.select("div.user-info")[0].find_all("a")
            href = elements[0].attrs["href"]
            user_info['id'] = re.search(r'\d+', href).group(0)
            user_info['username'] = elements[0].text
            user_info['reputation'] = update_info.select('span.reputation-score')[0].text
            user_info['badges'] = update_info.select("span.badges")[0].attrs["title"]
            try:
                elements[1]
            except IndexError:
                pass
            else:
                user_info['website'] = elements[1].attrs["href"]
            if update_info.select("img.flag"):
                flag = update_info.select("img.flag")[0].attrs["alt"]
                user_info['country'] = re.sub("flag of ", "", flag)

        return user_info
def parse_user_info(update_info):
        user_info = {}
        if update_info.select("div.user-info"):
            # Get all the <a> elements in the container. First <a> contains the user
            # information, second one (if exists), the website of the user.
            elements = update_info.select("div.user-info")[0].find_all("a")
            href = elements[0].attrs["href"]
            user_info['id'] = re.search(r'\d+', href).group(0)
            user_info['username'] = elements[0].text
            user_info['reputation'] = update_info.select('span.reputation-score')[0].text
            user_info['badges'] = update_info.select("span.badges")[0].attrs["title"]
            try:
                elements[1]
            except IndexError:
                pass
            else:
                user_info['website'] = elements[1].attrs["href"]
            if update_info.select("img.flag"):
                flag = update_info.select("img.flag")[0].attrs["alt"]
                user_info['country'] = re.sub("flag of ", "", flag)

        return user_info
def parse_user_info ( update_info ) : user_info = { } if update_info . select ( "div.user-info" ) : # Get all the <a> elements in the container. First <a> contains the user # information, second one (if exists), the website of the user. elements = update_info . select ( "div.user-info" ) [ 0 ] . find_all ( "a" ) href = elements [ 0 ] . attrs [ "href" ] user_info [ 'id' ] = re . search ( r'\d+' , href ) . group ( 0 ) user_info [ 'username' ] = elements [ 0 ] . text user_info [ 'reputation' ] = update_info . select ( 'span.reputation-score' ) [ 0 ] . text user_info [ 'badges' ] = update_info . select ( "span.badges" ) [ 0 ] . attrs [ "title" ] try : elements [ 1 ] except IndexError : pass else : user_info [ 'website' ] = elements [ 1 ] . attrs [ "href" ] if update_info . select ( "img.flag" ) : flag = update_info . select ( "img.flag" ) [ 0 ] . attrs [ "alt" ] user_info [ 'country' ] = re . sub ( "flag of " , "" , flag ) return user_info
Parse the user information of a given HTML container.

        The method parses all the available user information in the container.
        If the class "user-info" exists, the method will get all the available
        information in the container. If not, if a class "tip" exists, it will be
        a wiki post with no user associated. Else, it can be an empty container.

        :param update_info: beautiful soup answer container element

        :returns: an object with the parsed information
Parse the user information of a given HTML container .