MKS22QA Notes for Friday 5/19/2017

Read the notes at least twice.

This is basically a set of examples on how to use your cgi and forms to make forms that make results. The goal is to make it so that you can make a form to submit any amount of information, and then make a python program that would be able to handle the information and do something with it.

Your original two assignments were to allow for file selection of your Word Counting program, and make a Temperature conversion site. These examples should help you in case you were not able to complete those.

This is a form, please view the source to see the actual HTML elements of the form. You will leave the method as "GET" for now, and you change the action to match the python file you want to link it to. You do not have to worry about multiple forms on a site unless your final project requires it. I hate peas. You do have to worry about having more than one input with the same name, this is generally a mistake. Each input should have a different name, except the radio buttons which are grouped by name. (so you can have 2 separate groups if you like)

I have provided several examples, and a python program to submit to. You can see the results of submitting this form by submitting it with some data. You can see the source code of the handler by viewing the text file which is named 'handler.txt'.

Regarding reading it twice: If you didn't notice that I dislike a certain food type, that is reason enough for your to challenge your belief that your reading comprehension skills are adequate.

Sample form:


Drop Down Chooser(Pick a pet):
Radio: (make a choice)


Fix your Book analysis + Temperature conversion before you move on to the new lab. NOW! Use your newfound skills to write a madlibs form/program. You will take a paragraph or two from a book you like, and allow the user to submit words to see the results. This will ultimately be due at a later date, but starting now and asking about the problems will make it easier, especially when I add a few more parts to the HW next week.

  1. Make a new directory ~/public_html/07madlibs , place all of the files for this lab in that directory
  2. Take a story excerpt (3 are posted on the course website) and save it as a text file story.txt
  3. Replace 5-10 words with easy to replace strings like $word1$ or *noun1* etc.
  4. Now make a form, that allows the user to submit 5-10 text boxes
  5. Label the box with the type of word you are replacing. like: noun, verb(an example of tense would be helpful), adverb, adjective, etc.
  6. Add a submit button!
  7. Write the program that responds to this form, by reading the story file, and replacing the appropriate words.
  8. Make sure the program prints the new story!

Some story excerpts:

Call me Ishmael. Some years ago- never mind how long precisely- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off- then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball.


'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.

"Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!"

He took his vorpal sword in hand;
Long time the manxome foe he sought-
So rested he by the Tumtum tree
And stood awhile in thought.


It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way--in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.