Skip to content

Instantly share code, notes, and snippets.

@matheusportela
Created March 31, 2017 12:06
Show Gist options
  • Save matheusportela/d500dc38ebcf72f4adcf341945ab8246 to your computer and use it in GitHub Desktop.
Save matheusportela/d500dc38ebcf72f4adcf341945ab8246 to your computer and use it in GitHub Desktop.
How to use simpletable to generate a table given some data
import simpletable
def main():
data = '''basesystem-10.0-7.el7.centos.noarch
checksum_data = 0280ee16df09be0cebf62695706598caed8ff5cba47de1fed625068a90a9ef68
checksum_type = sha256
from_repo = anaconda
from_repo_revision = 1489513119
from_repo_timestamp = 1489513374
installed_by = 4294967295
reason = user
releasever = 7
var_uuid = 1876dc58-f5e1-4b9f-ae70-1f2edafce17b
bash-4.2.46-21.el7_3.x86_64
checksum_data = 0d915cb576545d236de9fc43c19cd503af669a1e7cdc030f6abc1a0e8006ef2e
checksum_type = sha256
from_repo = anaconda
from_repo_revision = 1489513119
from_repo_timestamp = 1489513374
installed_by = 4294967295
reason = user
releasever = 7
var_uuid = 1876dc58-f5e1-4b9f-ae70-1f2edafce17b
bc-1.06.95-13.el7.x86_64
checksum_data = 1f6f6a73954496f15fa82ccf8606f5673015fbaa545acf13704221d35983ccbb
checksum_type = sha256
from_repo = anaconda
from_repo_revision = 1489513119
from_repo_timestamp = 1489513374
installed_by = 4294967295
reason = dep
releasever = 7
var_uuid = 1876dc58-f5e1-4b9f-ae70-1f2edafce17b
32:bind-libs-9.9.4-38.el7_3.2.x86_64
checksum_data = 102cdd935e72edc2c3eb7f3997eb86b66bd88d0db7c3c67481d46be5e33d1032
checksum_type = sha256
from_repo = anaconda
from_repo_revision = 1489513119
from_repo_timestamp = 1489513374
installed_by = 4294967295
reason = dep
releasever = 7
var_uuid = 1876dc58-f5e1-4b9f-ae70-1f2edafce17b'''
lines = data.splitlines()
header_row = [
'source', 'checksum_data', 'checksum_type', 'from_repo',
'from_repo_revision', 'from_repo_timestamp', 'installed_by', 'reason',
'releasever', 'var_uuid'
]
table_data = []
while lines:
line_data = [lines.pop(0)] # source
line_data.extend([lines.pop(0).split(' = ')[-1] for _ in range(9)])
table_data.append(line_data)
table = simpletable.SimpleTable(table_data, header_row=header_row)
page = simpletable.HTMLPage()
page.add_table(table)
page.save('test.html')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment