from bs4 import BeautifulSoup
import webbrowser

soup = BeautifulSoup()
body = soup.new_tag('body align=center style=background-color:yellowgreen')
soup.insert(0, body)
table = soup.new_tag('table align=center bgcolor=moccasin border=5 cellpadding=3 cellspacing=3')
body.insert(0, table)

with open('report.txt') as infile:
    title_s = soup.new_tag('h2')
    title_s.string = "Q - B U I L D E R"
    table.insert(0, title_s)
    for line in infile:
        row = soup.new_tag('tr')
        col1 = list(line.split('\n'))
        col1 = [ each for each in col1 if each != '']
        for coltext in col1:
            col = soup.new_tag('td')
            col.string = coltext
            row.insert(0, col)
        table.insert(len(table.contents), row)

with open('index.html', 'w') as outfile:
    outfile.write(soup.prettify())

webbrowser.open('index.html')

## https://stackoverflow.com/questions/24715027/converting-text-file-to-html-file-with-python

