Cgi Counter

Nomad nomad*** at ***freemail.absa.co.za
Tue Oct 16 09:28:33 EDT 2001


On Fri, 12 Oct 2001 12:59:04 -0700 (PDT), Neal Irwin
<sap2002us at yahoo.com> wrote:

>Does anyone have sample code for a web-page hit
>counter. I was curious what one would look like in
>Python. I have made one in Perl and would like to
>compare them. 
>
>Thanks

# Begin counter code :::
## $Id: default.py,v 1.1 2001-05-24 18:11:06+02 Nomad Exp $

import string

print "Content-Type: text/html\n\n"

fileRead = open('count.txt', 'r')

intHits = string.strip(fileRead.read())

# print "<p>intHits = " + intHits + "</p>"

if intHits == '':
	intHits = 0

fileRead.close()

intHits = string.atoi(intHits) + 1

fileWrite = open('count.txt', 'w')
fileWrite.write(str(intHits))
fileWrite.close

# followed by a long print """...""" containing
# the html template that uses the counter data.

# End counter code :::

Pretty simple, but it works...

HTH

-- 
Nomad

Wondering of the vast emptyness of the 'net
in search of something cool.



More information about the Python-list mailing list