'Parses found files, prints formatted output for DDG Fathead to stdout.'

def print_output(self):

    for filename in self.api_files:
        html_data = open(filename).read()
        soupy = BeautifulSoup(html_data, 'html.parser')
        for element in soupy.find_all('dl', {'class': 'class'}):
            anchor_link = ''
            if element.find('a', {'class': 'headerlink'}):
                anchor_link = element.find('a', {'class': 'headerlink'})['href']
            code = ''
            description = ''
            tags_to_replace = ['method', 'classmethod', 'function', 'attribute', 'exception']
            for tag_to_replace in tags_to_replace:
                for tag in element.find_all('dl', {'class': tag_to_replace}):
                    tag_code = ''
                    tag_description = ''
                    for item in tag.dt.contents:
                        tag_code += str(item)
                    tag_code = self._clean_html_tags(tag_code)
                    for item in tag.dd.contents:
                        tag_description += str(item)
                    tag_description = self._clean_html_tags(tag_description)
                    abstract = ((((('<section    class="prog_container">' + '<pre><code>') + tag_code) + '</pre></code><p>') + tag_description) + '</p></section>')
                    tag_title = tag.dt['id']
                    with open('redirects.txt', 'a') as f:
                        f.write('{},    {}\n'.format(tag_title.replace('.', '    '), tag_title))
                    tag_anchor_link = ''
                    if tag.find('a', {'class': 'headerlink'}):
                        tag_anchor_link = tag.find('a', {'class': 'headerlink'})['href']
                    filename_removed_dir = filename.replace('download/', '')
                    headerlink = ((self.baseurl + filename_removed_dir) + tag_anchor_link)
                    output_line = ''
                    output_line += (tag_title + ' DCTB ')
                    output_line += ('A' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += ('' + ' DCTB ')
                    output_line += (abstract + ' DCTB ')
                    output_line += headerlink
                    if output_line:
                        print output_line
                    tag.decompose()
            output_line = ''
            for item in element.dt.contents:
                code += str(item)
            code = self._clean_html_tags(code)
            code = self._clean_code_tags(code)
            for item in element.dd.contents:
                description += str(item)
            description = self._clean_html_tags(description)
            abstract = ((((('<section    class="prog_container">' + '<pre><code>') + code) + '</pre></code><p>') + description) + '</p></section>')
            title = element.dt['id']
            with open('redirects.txt', 'a') as f:
                f.write('{},    {}\n'.format(title.replace('.', '    '), title))
            filename_removed_dir = filename.replace('download/', '')
            headerlink = ((self.baseurl + filename_removed_dir) + anchor_link)
            output_line += (title + ' DCTB ')
            output_line += ('A' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += ('' + ' DCTB ')
            output_line += (abstract + ' DCTB ')
            output_line += headerlink
            if output_line:
                print output_line
            element.decompose()
        tags_to_replace = ['method', 'classmethod', 'function', 'attribute', 'exception', 'describe', 'data']
        for tag_to_replace in tags_to_replace:
            for tag in soupy.find_all('dl', {'class': tag_to_replace}):
                anchor_link = ''
                if tag.find('a', {'class': 'headerlink'}):
                    anchor_link = tag.find('a', {'class': 'headerlink'})['href']
                tag_code = ''
                tag_description = ''
                for item in tag.dt.contents:
                    tag_code += str(item)
                tag_code = self._clean_html_tags(tag_code)
                tag_code = self._clean_code_tags(tag_code)
                for item in tag.dd.contents:
                    tag_description += str(item)
                tag_description = self._clean_html_tags(tag_description)
                output_line = ''
                abstract = ((((('<section    class="prog_container">' + '<pre><code>') + tag_code) + '</pre></code><p>') + tag_description) + '</p></section>')
                title = tag.dt['id']
                with open('redirects.txt', 'a') as f:
                    f.write('{},    {}\n'.format(title.replace('.', '    '), title))
                tag.decompose()
                filename_removed_dir = filename.replace('download/', '')
                headerlink = ((self.baseurl + filename_removed_dir) + anchor_link)
                output_line += (title + ' DCTB ')
                output_line += ('A' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += ('' + ' DCTB ')
                output_line += (abstract + ' DCTB ')
                output_line += headerlink
                if output_line:
                    print output_line
