Created
April 23, 2015 22:00
-
-
Save noisychannel/86f7eb73749c49ef472a to your computer and use it in GitHub Desktop.
Interleave output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import codecs | |
sentenceId = 0 | |
def readFiles(files, labels): | |
global sentenceId | |
sentenceId = sentenceId + 1 | |
print "<p><h3>Sentence " + str(sentenceId) + "</h3>" | |
print "<table>" | |
for i, label in enumerate(labels): | |
currentLine = files[i].readline() | |
if currentLine == "": | |
return True | |
break | |
currentLine = currentLine.strip() | |
print "<tr><td><b>" + label + "</b></td><td>" + currentLine + "</td></tr>" | |
print "</table></p>" | |
if len(sys.argv) < 3: | |
print "Usage : interleave labels(comma-sep) file1 file2 ..." | |
sys.exit() | |
noFiles = len(sys.argv) - 2 | |
labels = sys.argv[1].split(",") | |
noLabels = len(labels) | |
if noFiles != noLabels: | |
print "The number of labels and files do no match" | |
sys.exit() | |
files = [] | |
# Open files and add them to a list | |
for i in range(len(sys.argv) - 2): | |
files.append(codecs.open(sys.argv[i+2])) | |
# Read files and add labels | |
print "<html><body>" | |
print "<head><meta charset=\"UTF-8\" /></head>" | |
print "<style>table, th, td {border: 1px solid black; border-collapse: collapse;} th,td {padding:15px;}</style>" | |
while True: | |
eofReached = readFiles(files, labels) | |
if eofReached: | |
break | |
print "</html></body>" | |
for fileHandle in files: | |
fileHandle.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment