2017-04-28 CSV to HTML - HW

posted Apr 28, 2017, 6:55 AM by Samuel Konstantinovich   [ updated Apr 28, 2017, 8:03 AM ]
Your python programs can output HTML.

We can write a python program that prints a valid (includes proper HTML skeleton) blank website (the body is empty).

TITLE = "INSERT TITLE HERE"
BODY = "Something here"

print """<!DOCTYPE html><html>
<html>
<head><title>"""+TITLE +"""</title></head>
<body>

""" +  BODY + """

</body></html>"""

Notice that you can use variables in your HTML string that make it easy to replace segments of your website.



CLASSWORK 1:
Write a python function that converts a 2D list, into an html table. 
L = ['a','b','c','d'], [1,2,3,12], ['fa','bu','lo','us'] ]
toHTMLTable( L ) 
Would return the string:

'''<table>
<tr>
   <th>a</th> <th>b</th> <th>c</th> <th>d</th> 
</tr>
<tr>
   <td>1</td> <td>2</td> <td>3</td> <td>12</td> 
</tr>
<tr>
   <td>fa</td> <td>bu</td> <td>lo</td> <td>us</td> 
</tr>
</table>'''

BEFORE WE CODE:
-If you could ask for a built in function to help you with this task , what would that function be?
-Is there a repeated non-trivial task in this problem that would be best put into a helper function?

NOW:
a) Write the helper function first
b) Write the toHTMLTable() function using that helper method.



Goal 2 - Homework due Tuesday May 2nd 8am. 


2010 SAT results:
https://data.cityofnewyork.us/Education/SAT-College-Board-2010-School-Level-Results/zt9s-n5aj/data
2012 SAT results:
https://data.cityofnewyork.us/Education/SAT-Results/f9bf-2cp4/data

1 Export these as a CSV. 
2 Read the data into python. Don't forget to include your header on this assignment!
3 Split it up appropriately.
4 Add a new column! "Total Score", and calculate the total score for each row of the data.
5 Convert the to an HTML table.
6 Output a complete website with your name on top and the SAT stats in an HTML table. Do this to both CSV files and output the text to SAT2010.html, SAT2012.html.
7. Place the html files into the folder:  ~/public_html/02SAT/ 
( ~ means your home directory)

Comments