Title: Welcome back to the Creativity and Computation LAB
1Welcome back to theCreativity and
ComputationLAB!
2This weeks class will be incredible!
3Please calm down, we know you are excited.
4We will spend todays session going over three
things
- Continued work on the Python tutorial
- An introduction to running CGI scripts
- Embedding Python within HTML scripts
5Next week we will have a break from coding and go
through a session on podcasting and RSS.
6First, a reminder.If you have a laptop, please
being it to CC Lab when possible.
7There are two reasons for bringing a laptop to
class
- If you have a Mac, you can do all of the stuff we
are doing on lta.parsons.edugt locally - You can save all of the files, scripts, and
programs we use to your own machine
8We really urge you to take advantage of the Mac
OS X if you can. Or figure out how to do this
stuff on Windows.Set it up on your own machine!
(Youll learn more.)
9We realize that there was a lot of info in the
Python tutorial. Lets take a moment to go
around the room and let people tell where they
are at, and talk about what functional Python
script they wrote (or didnt write).
10You will have the next couple of weeks to
continue learning about Python.
11Remember, try to write something that is
functional. You will find many ways to apply
tools like Python to your everyday design work.
Pick a small problem that you think Python might
solve, and give it a shot.
12We will schedule an evening or weekend Python
workshop if there is the need/demand.Speak up!
13We are going use Python to create web pages.We
will do this by using a Python HTML
preprocessor.
14There are like 7 trillion different types of
preprocessors in the world. Some create HTML,
many do other things.
15Preprocessor is a good word to know. If you are
engaged in small talk with someone you dont
like, simply saypreprocessor(They will
depart immediately)
16Anyway, basically all of this happens by
embedding Python code into HTML.The Python
code is executed using a basic web server
technology called CGI.
17Many of you may have worked with CGI in the past.
It is the technology used to process HTML Forms.
18First we need to make sure that CGI is set up and
working on your lta.parsons.edugt account.
19Do this by creating the directory cgi-bin
within your public_html directory, if it isnt
already there.
20Then check the permissions on the CGI directory
(use the command ls -l to do this. The results
should read something likedrwxr-xr-x 2 sven
staff 4096 Sep 13 1214 cgi-bin
21If your cgi-bin doesnt have the
permissionsdrwxr-xr-xA quick way to change
the permissions to the correct setting ischmod
755 cgi-bin
22We told you last week that you would be checking
and changing the permissions on your web files a
lot. This is a good example. If a folder isnt
readable or executable, things wont work
right.
23When you have the cgi-bin folder set up right,
you want to test it with a script.Go to the lab
site and access the CGI test script.
24Open a new text file (use the text editor nano)
in your lta.parsons.edugt server account, name it
tester.cgi, and type in the contents of that
file.
25Save the file astester.cgiinto your cgi-bin
directory.
26Save the file astester.cgiinto your cgi-bin
directory.
27We are asking you to do it this way (instead of
just cutting and pasting) to make sure there are
no invisible characters in the file. Its
also good practice on using Unix text editors.
28Try running the file by going to the
URLhttp//a.parsons.edu/username/cgi-bin/test
er.cgi If the CGI is working, ou should get a
page that says TEST
29Go in and mess around with the contents of your
tester.cgi file. Make it say something else.
30This test CGI file is calling a language called
Perl. You can tell what language a cgi file
is calling by looking at the sh-bang (!) line,
usually the first line of a cgi file.
31We wont be using Perl in CC Lab, but it is a
very common, very powerful scripting language in
use all over the web.
32Python will use CGI in exactly the same way as
the tester.cgi file used Perl. Basically, we
will create a HTML file, which will in turn call
a Python file which will be present in the
cgi-bin folder.
33We will be working with a Python preprocessor
calledPyHP(The link to the developers site
is on the CC Lab site)
34Go to the CC Lab site and download the PyHP tar
fileto your local machine.
35Now upload it to your cgi-bin directory (using
secure ftp, or sftp)Then uncompress itgunzip
PyHP.tgz Then untar ittar -xf PyHP.tar
36Once youve done all of this there will be a
PyHP directory within your cgi-bin
directory.There is a file within that directory
called pyhp.py. Thats the main file we will be
using.
37Also in that directory you will find a sample
directory, which contains a test file.Our
challenge is to get that test file to work.
38Notice that the sh-bang line in that file is
not quite the same as the earlier one that called
Perl.You must always include the full path to
your pyhp.py file.
39Also note that the file has .pyhp appended
instead of just .py. This is a must for files
using PyHP.
40You can go to the PyHP site (link on the CC Lab
site), and review the (rather brief)
documentation.
41We will be running PyHP as stand alone (using
CGI).
42Your assignment this week is to get this test
PyHP file to run on your lta.parsons.edugt web
site.Change the path to your path (replace Ben
Bacons path)
43One final noteThere are actually two
development projects out there called PyHP. Use
the one linked to on the CC Lab site, developed
byChristopher A. Craig
44Good Luck!