Simple Dictionary Question

Ben Ocean zope at thewebsons.com
Fri May 4 22:59:08 CEST 2001


At 01:51 PM 5/4/2001 -0700, you wrote:
>You need to include more of your script (maybe the whole thing).
>There is no clue about what v is supposed to be, or what i is
>supposed to be, or what the script is trying to do.

Oops.
 >>>
for i in form.keys():
    v = form[i].value
    save.append(i + ": " + v + "\n")
    if form.has_key("token"):
      if i == "bladename":
        bladename = v
      if i == "bladephone":
        bladephone = v
      if i == "bladeemail":
        bladeemail = v
      if i == "token":
        token = v
<<<
The *blade* things are keys: I need to extract their values. The variables 
will be set only if *token* is set. Why can't I extract the value of the 
variables? If you really want to see the whole script, here it is. Thanks 
in advance for your help,
BenO

SCRIPT FOLLOWS...

#!/usr/bin/python

import cgi, os
import string

print "Content-type: text/html\n\n"
form = cgi.FieldStorage()

save = []
for i in form.keys():
    v = form[i].value
    save.append(i + ": " + v + "\n")
    if form.has_key("token"):
      if i == "bladename":
        bladename = v
      if i == "bladephone":
        bladephone = v
      if i == "bladeemail":
        bladeemail = v
      if i == "token":
        token = v
data = string.join(save,"")
data = string.replace(data, "%%", "<br>")
data = string.replace(data, "PrintablePageHeading: <!--Kelley Logo graphic 
begins here-->", "")
data = string.replace(data, "<TABLE WIDTH=590 border=0><TR 
valign=\"top\"><TD width=\"258\">", "")
data = string.replace(data, "<IMG SRC=\"/kbbhead.gif\" width=258 height=72 
alt=\"Kelley Blue Book\">", "")
data = string.replace(data, "<td><img src=\"/images/modes/clear.gif\" 
border=\"0\" width=\"150\"></td></TR></TABLE>", "")
data = string.replace(data, "<!--logo ends here-->", "")
array = string.split(data, "QueryWindowStatus")
table = string.maketrans("`~@#$^&*+{}\|[]?", "----------------")
_saver = string.translate(array[0], table)

try:
  if token == "printer":
    print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\" 
\"http://www.w3.org/TR/REC-html40/frameset.dtd\"> \n"
    print "<HTML><HEAD>\n"
    print "<font style=\"font: 17px verdana\">\n"
    file = open("outfile.txt", "r")
    line = file.readline()
    print line
    file.close()
    print "</BODY>\n"
    print "</HTML>\n"
  if token == "mail":
   print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\" 
\"http://www.w3.org/TR/REC-html40/frameset.dtd\"> \n"
   print "<HTML><HEAD>\n"
   print "<meta http-equiv=\"content-type\" content=\"text/html; 
charset=iso-8859-1\">\n"
   print "<meta name=\"author\" content=\"This web site developed by 
TheWebsons.com. You may reach us at our web site, or by dialing 
360-855-0899.\">\n"
   print "<meta name=\"description\" content=\"Blade Chevrolet gives you 
all the information you need to shop online, including dealer costs!\">\n"
   print "<meta name=\"keywords\" content=\"preowned cars, preowned trucks, 
preowned RVs, new cars, new trucks, new RVs, recreational vehicles, Chevy, 
Chevrolet, Ford, Honda, Buick, Chrysler, Volkswagon, Cadillac, Lincoln, 
Oldsmobile, Pontiac\">\n"
   print "<meta http-equiv=\"distribution\" content=\"Global\">\n"
   print "<meta http-equiv=\"robots\" content=\"index all, follow all\">\n"
   #print "<SCRIPT TYPE=\"text/javascript\" LANGUAGE=JavaScript>\n"
   #print "<!--\n"
   #print "if (document.../images) {\n"
   #print "w = new Image();\n"
   #print "w.src = \"../images/new4.gif\";\n"
   #print ";\n"
   #print "won = new Image();\n"
   #print "won.src = \"../images/new5.gif\";\n"
   #print "}\n"
   #print "function image_activate(imageName) {\n"
   #print "if (document.../images) {\n"
   #print "imageOn = eval(imageName + \"on.src\");\n"
   #print "document [imageName].src = imageOn;\n"
   #print "}\n"
   #print "}\n"
   #print "function image_inactivate(imageName) {\n"
   #print "if (document.../images) {\n"
   #print "imageOff = eval(imageName + \".src\");\n"
   #print "document [imageName].src = imageOff;\n"
   #print "}\n"
   #print "}\n"
   #print "// -->\n"
   #print "</SCRIPT>\n"
   print "<style>\n"
   print ".heading { position: absolute; top: 100; left: 280 }\n"
   print ".headings { font-size: 25px; font-weight: 700; color: #0033ff; 
font-style: script, nuptialscript, georgia, lucinda sans, arial, helvetica }\n"
   print ".frame { position: absolute; top: 150; left: 50 }\n"
   print "</style>\n"
   print "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style2.css\">\n"
   print "<TITLE> Your Vehicle </TITLE>\n"
   print "</HEAD>\n"
   print "<BODY background=\"../images/template2-2-a.gif\" 
bgproperties=\"fixed\">\n"
   print "<form method=post action=\"kbb.cgi?token=sendit\">"
   print "<span class=\"logo2\"><img src=\"../images/logo2.gif\" 
border=\"0\" alt=\"Blade Chevrolet logo\"></span>\n"
   print "<span class=\"home\"><a href=\"index.html\"><img 
src=\"../images/home2.gif\" border=\"0\" alt=\"Home\"></a></span>\n"
   print "<span class=\"pre\"><a href=\"Pre-Owned\"><img 
src=\"../images/pre-owned3.gif\" border=\"0\" alt=\"Pre-Owned 
Vehicles\"></a></span>\n"
   print "<span class=\"commercial\"><a href=\"Commercial\"><img 
src=\"../images/commercial2.gif\" border=\"0\" alt=\"Commercial 
Vehicles\"></a></span>\n"
   print "<span class=\"new_vehicles\"><a href=\"New/\" 
onMouseOver=\"image_activate('w')\" 
onMouseOut=\"image_inactivate('w')\"><img src=\"../images/new4.gif\" 
border=\"0\" name=\"w\" usemap=\"#n\" alt=\"New Cars & Trucks\"></a>\n"
   print "<map name=\"n\">\n"
   print "<area shape=\"rect\" coords=\"0,0,100,32\" href=\"New/Cars/\" 
alt=\"New Cars\">\n"
   print "<area shape=\"rect\" coords=\"100,0,204,32\" href=\"New/Trucks/\" 
alt=\"New Trucks\">\n"
   print "</map></span>\n"
   print "<span class=\"rvs\"><a href=\"RVs/\"><img 
src=\"../images/rvs2.gif\" border=\"0\" alt=\"RV's\"></a></span>\n"
   print "<span class=\"service\"><a href=\"Service.html\"><img 
src=\"../images/service2-cars.gif\" border=\"0\" alt=\"Service\"></a></span>\n"
   print "<span class=\"parts\"><a href=\"Parts.html\"><img 
src=\"../images/parts2-cars.gif\" border=\"0\" alt=\"Parts\"></a></span>\n"
   print "<span class=\"autobody\"><a href=\"Auto_Body.html\"><img 
src=\"../images/autobody2-cars.gif\" border=\"0\" alt=\"Auto 
Body\"></a></span>\n"
   print "<span class=\"staff\"><a href=\"Staff.html\"><img 
src=\"../images/staff2-cars.gif\" border=\"0\" alt=\"Staff\"></a></span>\n"
   print "<span class=\"directions\"><a href=\"Directions.html\"><img 
src=\"../images/directions2-cars.gif\" border=\"0\" 
alt=\"Directions\"></a></span>\n"
   print "<span class=\"history\"><a href=\"Our_History.html\"><img 
src=\"../images/history2-cars.gif\" border=0 alt=\"Our History\"></a></span>\n"
   print "<span class=\"email\"><a href=\"Directions_Body_Shop.html\"><img 
src=\"../images/email.gif\" border=0 alt=\"E-Mail Us!\"></a></span>\n"
   print "<span class=\"email1\"><span class=\"email2\"><a 
href=\"mailto:bodyshop at bladechevy.com\">E-Mail Us!</a></span></span>\n"
   print "<span class=\"heading\"><span class=\"headings\">Here's Your 
Vehicle!</span></span>\n"
   print "<span class=\"frame\">\n"
   print "<center><font style=\"font: 17px verdana\">\n"
   print "Great! Please fill out a little more information, and we'll get 
back to you soon!<br> <br>\n"
   print "Please tell us your name: <input type=text name=\"bladename\" 
size=20><br>"
   print "Please tell us your phone number: <input type=text 
name=\"bladephone\" size=10><br>"
   print "Please tell us your email address: <input type=text 
name=\"bladeemail\" size=20><br>"
   print "<input type=hidden name=\"token\" value=\"sendit\">"
   print "<input type=submit>"
   print "</font></span>\n"
   print "</form>"
   print "</BODY>\n"
   print "</HTML>\n"
  if token == "sendit":
    file = open("outfile.txt", "r")
    line = file.readline()
    aaaa = "Visitor\'s Name: "
    bbbb = "\nVisitor\'s Phone: "
    cccc = "\nVisitor\'s Email: "
    dddd = "\n\n"
    blade = string.join(aaaa, bladename, bbbb, bladephone, cccc, 
bladeemail, dddd)
    line = string.join(blade, line)
    import smtplib
    server = smtplib.SMTP("localhost")
    server.sendmail("beno at thewebsons.com", "beno at thewebsons.com", "Subject: 
Blade Chevy Car Inquiry\n\n%s" % line)
    file.close()
    print "<html><head><meta http-equiv=\"Refresh\" content=\"0; 
URL=http://www.bladechevy.com/New/Thank_You.html\">"
    server.quit()
except NameError:
   file = open("outfile.txt", "w")
   file.write(_saver)
   file.close()
   print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\" 
\"http://www.w3.org/TR/REC-html40/frameset.dtd\"> \n"
   print "<HTML><HEAD>\n"
   print "<meta http-equiv=\"content-type\" content=\"text/html; 
charset=iso-8859-1\">\n"
   print "<meta name=\"author\" content=\"This web site developed by 
TheWebsons.com. You may reach us at our web site, or by dialing 
360-855-0899.\">\n"
   print "<meta name=\"description\" content=\"Blade Chevrolet gives you 
all the information you need to shop online, including dealer costs!\">\n"
   print "<meta name=\"keywords\" content=\"preowned cars, preowned trucks, 
preowned RVs, new cars, new trucks, new RVs, recreational vehicles, Chevy, 
Chevrolet, Ford, Honda, Buick, Chrysler, Volkswagon, Cadillac, Lincoln, 
Oldsmobile, Pontiac\">\n"
   print "<meta http-equiv=\"distribution\" content=\"Global\">\n"
   print "<meta http-equiv=\"robots\" content=\"index all, follow all\">\n"
   #print "<SCRIPT TYPE=\"text/javascript\" LANGUAGE=JavaScript>\n"
   #print "<!--\n"
   #print "if (document.../images) {\n"
   #print "w = new Image();\n"
   #print "w.src = \"../images/new4.gif\";\n"
   #print ";\n"
   #print "won = new Image();\n"
   #print "won.src = \"../images/new5.gif\";\n"
   #print "}\n"
   #print "function image_activate(imageName) {\n"
   #print "if (document.../images) {\n"
   #print "imageOn = eval(imageName + \"on.src\");\n"
   #print "document [imageName].src = imageOn;\n"
   #print "}\n"
   #print "}\n"
   #print "function image_inactivate(imageName) {\n"
   #print "if (document.../images) {\n"
   #print "imageOff = eval(imageName + \".src\");\n"
   #print "document [imageName].src = imageOff;\n"
   #print "}\n"
   #print "}\n"
   #print "// -->\n"
   #print "</SCRIPT>\n"
   print "<style>\n"
   print ".heading { position: absolute; top: 100; left: 280 }\n"
   print ".headings { font-size: 25px; font-weight: 700; color: #0033ff; 
font-style: script, nuptialscript, georgia, lucinda sans, arial, helvetica }\n"
   print ".frame { position: absolute; top: 150; left: 50 }\n"
   print "</style>\n"
   print "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style2.css\">\n"
   print "<TITLE> Your Vehicle </TITLE>\n"
   print "</HEAD>\n"
   print "<BODY background=\"../images/template2-2-a.gif\" 
bgproperties=\"fixed\">\n"
   print "<span class=\"logo2\"><img src=\"../images/logo2.gif\" 
border=\"0\" alt=\"Blade Chevrolet logo\"></span>\n"
   print "<span class=\"home\"><a href=\"index.html\"><img 
src=\"../images/home2.gif\" border=\"0\" alt=\"Home\"></a></span>\n"
   print "<span class=\"pre\"><a href=\"Pre-Owned\"><img 
src=\"../images/pre-owned3.gif\" border=\"0\" alt=\"Pre-Owned 
Vehicles\"></a></span>\n"
   print "<span class=\"commercial\"><a href=\"Commercial\"><img 
src=\"../images/commercial2.gif\" border=\"0\" alt=\"Commercial 
Vehicles\"></a></span>\n"
   print "<span class=\"new_vehicles\"><a href=\"New/\" 
onMouseOver=\"image_activate('w')\" 
onMouseOut=\"image_inactivate('w')\"><img src=\"../images/new4.gif\" 
border=\"0\" name=\"w\" usemap=\"#n\" alt=\"New Cars & Trucks\"></a>\n"
   print "<map name=\"n\">\n"
   print "<area shape=\"rect\" coords=\"0,0,100,32\" href=\"New/Cars/\" 
alt=\"New Cars\">\n"
   print "<area shape=\"rect\" coords=\"100,0,204,32\" href=\"New/Trucks/\" 
alt=\"New Trucks\">\n"
   print "</map></span>\n"
   print "<span class=\"rvs\"><a href=\"RVs/\"><img 
src=\"../images/rvs2.gif\" border=\"0\" alt=\"RV's\"></a></span>\n"
   print "<span class=\"service\"><a href=\"Service.html\"><img 
src=\"../images/service2-cars.gif\" border=\"0\" alt=\"Service\"></a></span>\n"
   print "<span class=\"parts\"><a href=\"Parts.html\"><img 
src=\"../images/parts2-cars.gif\" border=\"0\" alt=\"Parts\"></a></span>\n"
   print "<span class=\"autobody\"><a href=\"Auto_Body.html\"><img 
src=\"../images/autobody2-cars.gif\" border=\"0\" alt=\"Auto 
Body\"></a></span>\n"
   print "<span class=\"staff\"><a href=\"Staff.html\"><img 
src=\"../images/staff2-cars.gif\" border=\"0\" alt=\"Staff\"></a></span>\n"
   print "<span class=\"directions\"><a href=\"Directions.html\"><img 
src=\"../images/directions2-cars.gif\" border=\"0\" 
alt=\"Directions\"></a></span>\n"
   print "<span class=\"history\"><a href=\"Our_History.html\"><img 
src=\"../images/history2-cars.gif\" border=0 alt=\"Our History\"></a></span>\n"
   print "<span class=\"email\"><a href=\"Directions_Body_Shop.html\"><img 
src=\"../images/email.gif\" border=0 alt=\"E-Mail Us!\"></a></span>\n"
   print "<span class=\"email1\"><span class=\"email2\"><a 
href=\"mailto:bodyshop at bladechevy.com\">E-Mail Us!</a></span></span>\n"
   print "<span class=\"heading\"><span class=\"headings\">Here's Your 
Vehicle!</span></span>\n"
   print "<span class=\"frame\">\n"
   print "<center><font style=\"font: italic 800 22px futura\">If you would 
like us to help you purchase this car, <a 
href=\"http://www.bladechevy.com/cgi-bin/kbb.cgi?token=mail\">click 
here!</a></center><br>\n"
   print "<center>For a printable version, <a 
href=\"http://www.bladechevy.com/cgi-bin/kbb.cgi?token=printer\">click 
here!</a></center><br> <br>\n"
   print "<font style=\"font: 17px verdana\">\n"
   print _saver
   print "</font></span>\n"
   print "</BODY>\n"
   print "</HTML>\n"







More information about the Python-list mailing list