Skip to content

Instantly share code, notes, and snippets.

@ejmurray
Created September 8, 2015 14:33
Show Gist options
  • Save ejmurray/62450101b2c89a39925f to your computer and use it in GitHub Desktop.
Save ejmurray/62450101b2c89a39925f to your computer and use it in GitHub Desktop.
Convert the referece data to a html output
#!/usr/bin/env python
"""
__author__ = 'Ernest Murray'
__Created__: 08/09/2015
This script takes the content of a file, in this case a tab separated file and
converts it to an html table. The headers for html file are contained in the text file.
The output is given in the sys.out field.
# https://goo.gl/Hn1nzf
# https://goo.gl/ZY5JYJ
"""
# TODO(EM): direct the output to a html file
import csv
from prettytable import PrettyTable
with open("data.txt", "r") as fp:
reader = csv.DictReader(fp, dialect='excel-tab')
ptable = PrettyTable(reader.fieldnames)
for rowdict in reader:
ptable.add_row([rowdict[fn] for fn in reader.fieldnames])
print ptable.get_html_string()
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment