Re: WWW-CGI python calls and the environment...

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Thu, 16 Jun 1994 15:38:17 -0400

On Jun 16, 12:00, "Jason B. Bluming" wrote:
>
> it *should* be simple....
> it *is* simple in python-based servers and whatnot, but for
> one reason or another I'm not getting NCSA's httpd to
> call a python script correctly (and yes, I am resetting the
> PYTHONPATH env var just in case, after CGI clobbers it)...
>
> anyone have a sample?
>

It IS simple! (or should be.) - What exactly are you doing?
And what exactly isn't working? ( and do you have the right
options turned on on your server, and is you script in a
directory where the server can access + execute it ? )

This is not linked into anywhere from our home page -
this was just my first try at a python cgi script.

You can look at the output by connecting to URL:
http://minsky.med.virginia.edu:8080/cgi-bin/Today.py

Not a particularly neat or orderly program - I was trying to
see if I understood the protocol ( and after 3 or 4 tries, I
think I finally do! ;-)

This SHOULD give (my) local-time,
( This is where I ran into the tzset() problem, although I do
believe that time should be available from a CGI environment
variable. )
cal output with today's data in <B>old<\B> and a fortune cookie
message. ( And it does do all that on *my* Mosaic/X11, at least. )

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics

#!/usr/local/bin/python

import time,posix,string,sys

if time.timezone == 0 :
time.TIME = time.time() - 14400.0 # TZ bug kludge
else: time.TIME = time.time()
day = repr(time.localtime( time.TIME )[2])
calout = posix.popen( 'cal', 'r' ).readlines()
mon=string.strip( calout[0] )
date=time.ctime(time.TIME)

print 'Content-type: text/html\n'
print '<TITLE>"Calendar:' +mon+ '" </TITLE>'
print '<HR>'
print '<H2>', date, '</H2>'
print '<HR>'
print '\n\n'
print '<pre>'
print calout[0]
print calout[1]
for line in calout[2:] :
i = string.find( line, day )
if i <= 0 :
print line
else:
print line[:i] + '<B>' + line[i:i+len(day)] + '</B>' + line[i+len(day):]

print '</pre>'

if 'DEBUG' in sys.argv[1:] :
if posix.environ.has_key('TZ') and posix.environ['TZ']:
print posix.environ['TZ']
else: print 'NO TZ'

print '<p>'
for line in posix.popen( '/usr/games/fortune' , 'r' ).readlines():
print line,
print '<p>'