2018-05-01

posted Apr 30, 2018, 5:21 PM by Konstantinovich Samuel   [ updated May 1, 2018, 9:51 AM ]
Do Now:
On Paper:
  Write a function makeRow(s)

s is a string in the format:
value1,value2,value3,...,valueN

Example:
line = "1,24,3"

 makeRow(line) would result in a valid HTML row in a string: 
(including spaces for indentation)

'''    <tr> 
      <td> 1 </td> 
      <td> 24 </td>
      <td> 3 </td> 
    </tr>'''



Classwork:

Write a function convertToTable(s).
The parameter is a string in the format:
valuea1,valuea2,valuea3,...,valueaN
valueb1,valueb2,valueb3,...,valuebN
...
valueX1,valueX2, valueX3,...,valueXN

so there are 1 or more lines (a..X)
each line has 1 or more values (1...n)
each line has the same number of values (rectangular table)

You are guaranteed at least 1 value by itself. 

Example:
csv = """1,2,3
4,5,8
2,2,2"""

 convertTable(csv) would result in a valid HTML table in a string: (including spaces for indentation)
'''  <table>
    <tr> 
      <td> 1 </td> 
      <td> 2 </td>
      <td> 3 </td> 
    </tr>
    <tr> 
      <td> 4 </td> 
      <td> 5 </td> 
      <td> 8 </td>
    </tr>
    <tr> 
      <td> 2 </td>
      <td> 2 </td>
      <td> 2 </td>
    </tr>
  </table>'''


Here is sample data:
'''id,first_name,last_name,email,ip_address
1,Franny,Vobes,fvobes0@prweb.com,160.238.25.191
2,Barthel,Ough,bough1@mail.ru,8.215.173.18
3,Crissy,Steagall,csteagall2@furl.net,87.29.11.55
4,Danny,Bartlosz,dbartlosz3@indiegogo.com,48.20.208.251
5,Flossie,Bruster,fbruster4@amazonaws.com,95.70.173.30
6,Simmonds,Coryndon,scoryndon5@meetup.com,43.211.172.60
7,Griffith,Mossbee,gmossbee6@ca.gov,31.226.71.188
8,Serena,Petranek,spetranek7@livejournal.com,128.224.182.13
9,Tirrell,Sellick,tsellick8@census.gov,47.5.73.120
10,Jess,Caulliere,jcaulliere9@istockphoto.com,87.206.223.153
11,Tonye,Haddrill,thaddrilla@disqus.com,224.7.243.118
12,Dillon,Gladhill,dgladhillb@cnn.com,183.251.76.53
13,Ursuline,Redemile,uredemilec@netscape.com,63.237.118.107
14,Aaren,Stanners,astannersd@fda.gov,172.151.43.226
15,Lorianne,Camden,lcamdene@bbc.co.uk,20.121.50.176
16,Bernadette,Emanuelov,bemanuelovf@ustream.tv,180.48.49.88
17,Hugibert,Fleckness,hflecknessg@so-net.ne.jp,168.230.209.177
18,Netta,Burkinshaw,nburkinshawh@parallels.com,145.166.79.150
19,Roley,Tollady,rtolladyi@omniture.com,69.120.30.138
20,Tommy,Cavee,tcaveej@google.nl,2.254.75.140'''


Final Step:
When you successfully make the table:
Try to make it a live python website in your 02tables directory. 
   You need to be able to do this from both class and home on future assignments.






Remember:
Your assignments must be like this:
http://homer.stuy.edu/~USERNAME/01homepage/profile.html
http://homer.stuy.edu/~USERNAME/02tables/tablesquares.html
http://homer.stuy.edu/~USERNAME/02tables/tableprimes.html
http://homer.stuy.edu/~USERNAME/03madlibslight/madlibs.py
http://homer.stuy.edu/~USERNAME/03madlibslight/madlibs2.py


Checklist:
Your python files that create websites should:
1. Have the proper header.
2. Print a website.
3. Run without errors
4. Placed in the correct directory. 
  4a. Exist in your public html directory on marge/homer etc. (in the computer lab)
  4b. Saved with unix line endings (check with gedit)
5. Have the executable flag set:
  5a) In school:
  -cd into the directory you placed your file.
  -run the command:
       chmod +x filename
  5b) at home using filezilla : 
      right click the file after uploading it, 
      click "file permissions" 
      make sure "executable" is checked off in all 3 sections.
6. open your file on the web server:
    marge.stuy.edu/~USERNAME/


Sample site:
#!/usr/bin/python
print "Content-type: text/html\n"

#help you see errors
import cgitb
cgitb.enable()

#static data
head = '''<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> html{ background-color: #000044; color: #33FF00; } </style> </head> <body>''' foot = ''' </body> </html>'''
#function definitions
def section1(): return "DO STUFF HERE<br>\n" def section2(): return "DO STUFF HERE<br>\n" def printBody(): print section1() print section2() print "Whatever you need to in here<br>"
#print the rest of the website
print head printBody() print foot




Comments