Page 337 -
P. 337

manage your data



                           CGI Magnets


                           You need a new CGI script called add_timing_data.py,
                           which processes the data from a form and displays the data on
                           your web server’s console screen. The CGI needs to query the
                           environment, arranging to display the logged data on one line.
                           The code exists, but most of it is all over the floor. Rearrange the
                           magnets to produce a working program.

            Don’t forget
            this line if you   #! /usr/local/bin/python3
            are running on
             Max OS X or   import cgi
             Linux.        import os                                                   There’s not much of a
                                                                                       response for now…so
                           import time                                                 just send back plain
                                                                                       text to the waiting
                           import sys
                                                                                       web browser.
                           import yate

                           print(yate.start_response('text/plain'))
              There’s really   addr = os.environ['REMOTE_ADDR']
              nothing new
              here.        host = os.environ['REMOTE_HOST']
                            method = os.environ['REQUEST_METHOD']
                           cur_time = time.asctime(time.localtime())
                           print(host + ", " + addr + ", " + cur_time + ": " + method + ": ",
                                          end='', file=sys.stderr)












                           print('OK.')
                                                                  form = cgi.FieldStorage()
                      end=' ',
                                           print(each_form_item + '->' + form[each_form_item].value,
                print(file=sys.stderr)
                                         for each_form_item in form.keys():      file=sys.stderr)



                                                                                      you are here 4    301
   332   333   334   335   336   337   338   339   340   341   342