from subprocess import getoutput
from os import system
page_start = """
Report on Examples and Lengths
"""
page_end = """
"""
# Generate page body
page_body = " Files from CS111
\n"
def get_file_len(filename):
return getoutput("wc " + filename).split()[0]
filenames = getoutput("dir").split()
python_lines = 0
other_lines = 0
for fn in filenames:
if "~" == fn[-1]:
continue
file_len = get_file_len(fn)
if "wc" in file_len:
continue
filetype = getoutput("file " + fn).lower()
if "python" in filetype and not "byte-compiled" in filetype:
page_body += "Python: " + fn + " (" + file_len + ")
\n"
python_lines += int(file_len)
else:
page_body += "Other: " + fn + " (" + file_len + ")
\n"
other_lines += int(file_len)
import matplotlib.pyplot as plt
plt.bar([0,2], [python_lines, other_lines])
plt.ylabel('Python Lines vs. Other Lines')
plt.savefig("chart.png")
page_body += "Total lines of Python: " + str(python_lines)
page_body += '
\n'
print("Writing output to webpage.html")
output_file = open("webpage.html", "w")
output_file.write(page_start)
output_file.write(page_body)
output_file.write(page_end)
output_file.close()
system("google-chrome webpage.html")