#!/usr/bin/python #----------------------------------------------------------------- # # CGI script for a page counter. To invoke in your HTML page # use: # # The file should contain the digits of the count (eg: "00123") # and the file should have write permissions for all. # # Inspired by an article in February '97 "Linux Journal" # written by Michel Vanaken. # # Written: by Richie Bielak 3/1/97 # #-------------------------------------------------------------------- import sys import cgi from strop import * # # Digits in .xbm format # zero = ["0x00", "0x1c", "0x36", "0x63", "0x63", "0x63", "0x63", "0x63", "0x63", "0x63", "0x63", "0x63", "0x63", "0x36", "0x1c", "0x00"] one = ["0x00", "0x18", "0x18", "0x1c", "0x1e", "0x1b", "0x18", "0x18", "0x18", "0x18", "0x18", "0x18", "0x18", "0x18", "0x7e", "0x00"] two = ["0x00", "0x1c", "0x36", "0x63", "0x60", "0x60", "0x60", "0x30", "0x1c", "0x06", "0x03", "0x03", "0x43", "0x43", "0x7f", "0x00"] three = ["0x00", "0x3e", "0x73", "0x61", "0x60", "0x60", "0x70", "0x3c", "0x70", "0x60", "0x60", "0x60", "0x61", "0x73", "0x3e", "0x00"] four = ["0x00", "0x10", "0x08", "0x08", "0x04", "0x04", "0x32", "0x32", "0x31", "0x7f", "0x30", "0x30", "0x30", "0x30", "0x30", "0x00"] five = ["0x00", "0x3f", "0x03", "0x03", "0x03", "0x03", "0x03", "0x3f", "0x70", "0x60", "0x60", "0x60", "0x61", "0x73", "0x3e", "0x00"] six = ["0x00", "0x7c", "0x46", "0x03", "0x03", "0x03", "0x03", "0x3b", "0x67", "0xc3", "0xc3", "0xc3", "0xc3", "0x66", "0x3c", "0x00"] seven = ["0x00", "0x7f", "0x41", "0x60", "0x60", "0x30", "0x30", "0x18", "0x18", "0x0c", "0x06", "0x06", "0x03", "0x03", "0x03", "0x00"] eight = ["0x00", "0x3e", "0x63", "0x63", "0x63", "0x63", "0x63", "0x3e", "0x63", "0x63", "0x63", "0x63", "0x63", "0x63", "0x3e", "0x00"] nine = ["0x00", "0x3e", "0x73", "0x61", "0x61", "0x61", "0x61", "0x73", "0x7e", "0x60", "0x60", "0x60", "0x60", "0x72", "0x3e", "0x00"] digits = [zero, one, two, three, four, five, six, seven, eight, nine] # # Print the bitmap for the digits # def print_digits (number): num_str = ("#define counter_width %d \n" % (len (number) * 8)) num_str = num_str + "#define counter_height 16\n" num_str = num_str + "static char counter_bits[] = {\n" i = 0 while i < 16: for d in number: num_str = num_str + digits [atoi (d)] [i] + "," i = i + 1 num_str = num_str + " 0x00};\n" return num_str # # Bump a counter and store in a file # def get_count (fname): infile = open (fname, "r") count_str = infile.read() infile.close () count = atoi (count_str) count = count + 1 outfile = open (fname, "w") outfile.write ("%04d" % count) outfile.close return count_str # # Main of the script # count_str = get_count (sys.argv[1]) count_str = print_digits (count_str) print "Content-type:image/x-bitmap" print print count_str print