2018-04-30 HW

posted Apr 30, 2018, 6:05 AM by Konstantinovich Samuel   [ updated Apr 30, 2018, 9:51 AM ]
Goal: Organize your data!

HW complete lab by Wed morning.

Do Now:
Make ALL files/directories lower case - you can do it!
This means your ~/public_html folder should look like this:
~/public_html/
   01homepage/
      profile.html
   02tables/
      tableprimes.html
      tablesquares.html
   03madlibslight
      madlibs.py
      madlibs2.py


We like to separate your data from your program. Otherwise things will get very ugly very fast :

books = []

#each of these can be many pages!
books.append('''REALLY LONG BOOK TEXT
asdf
asdf
asdf
asdf
asdf
asdf''')  

#each of these can be many pages!
books.append('''REALLY LONG DORIAN GREY TEXT
spooky!
oooh scary...
immortality
blah blah
''')

#each of these can be many pages!
books.append('''REALLY LONG TREASURE ISLAND TEXT
yarrr
avast!
Where be my long johns?
gold!
''')
#Code here that works with the books.

We often separate the data from the code. Your madlibs2.py will not have any book text in it!
books = []
books.append( getText("book1.txt") )
books.append( getText("book2.txt") )
books.append( getText("book3.txt") )

1. Save your books in separate text files. This should be plain text with $NOUN$ $VERB$ etc But SHOULD HAVE NO HTML TAGS!
dorian.txt
moby.txt
jabber.txt
treasure.txt

2. Make a list of all the books names, and all the poem names. You can now loop through them to open any number of books!
bookFiles = ['moby.txt','dorian.txt','treasure.txt']
poems = ['jabber.txt']

We previously learned to open a file and read the text, you have to ressurrect your old skills for this!

3. Focus on the books first. Write a function 
bookToHTML(filename)  
to read in the file, and turn it into HTML:
3a. Put paragraph tags around the paragraps. 
3b. Put a header with the book title (you can make a separate list of tiles of each poem)
e.g. each index corresponds, so the filename and title of index 0 match
bookTitles = [ "White Fang", "Bram Stoker's Dracula" ]
bookFiles = ["fang.txt" , "Drac.txt" ]


4. Do something similar for the poem
poemToHTML(filename)
4a. Put <br> for each newline so that the poem retains the formatting.
4b. Put a header with the poem title (you can make a separate list of tiles of each poem)

5. Loop through all book file names, and poem filenames:
Turn it into HTML
Replace the words like in the previous lab include color/font style
(optionally different colors for different kinds of words)
Print out the new version of the book.

6. Place <hr> tags between each title.

7. Pick your favorite poem and add it to the poem list, replace some of the words with $NOUN$ $VERB$ etc.

8. Randomly choose to use either: normal word lists or the themed words list for the entire page.
    8a. When you choose normal, every book/poem gets normal words, when you choose themed, they all use the themed list.
8b. Choose a different background color/font color for each theme. You can have 2 external CSS files, or 2 different internal style tags.


Final state: Due Wed Morning
-Your py file has no book text in it, instead it reads from data files.
-The data files have no HTML, just plain text and $wordtype$ replacements.
-You have 3 books, 2 poems on display.
I included treasure island in the lecture notes.
You need to pick a 2nd poem.
-The title of each book is included as a header.
-Each refresh looks different.
-You randomly get one of 2 themes of words for the entire page.
-Each theme has a different color for the entire page.
-The filename is madlibs2.py


treasureIsland = '''SQUIRE TRELAWNEY, Dr. Livesey, and the rest of these gentlemen having
asked me to write down the whole particulars about Treasure Island, from
the beginning to the end, keeping nothing back but the bearings of the
island, and that only because there is still treasure not yet lifted, I
take up my pen in the year of grace 17__ and go back to the time when
my father kept the Admiral Benbow inn and the brown old seaman with the
sabre cut first took up his lodging under our roof.

I remember him as if it were yesterday, as he came plodding to the
inn door, his sea-chest following behind him in a hand-barrow--a
tall, strong, heavy, nut-brown man, his tarry pigtail falling over the
shoulder of his soiled blue coat, his hands ragged and scarred, with
black, broken nails, and the sabre cut across one cheek, a dirty, livid
white. I remember him looking round the cover and whistling to himself
as he did so, and then breaking out in that old sea-song that he sang so
often afterwards:

          "Fifteen men on the dead man's chest--
             Yo-ho-ho, and a bottle of rum!"

in the high, old tottering voice that seemed to have been tuned and
broken at the capstan bars. Then he rapped on the door with a bit of
stick like a handspike that he carried, and when my father appeared,
called roughly for a glass of rum. This, when it was brought to him,
he drank slowly, like a connoisseur, lingering on the taste and still
looking about him at the cliffs and up at our signboard.'''
Comments