#!/usr/bin/env python # # See http://saksena.net/partygames/bingo/ for more details. # No warranties of any kind. Standard disclaimers apply. License == Common # Sense, or MPL (Mozilla Public License) # # Gagan Saksena # 10/13/01 # 09/13/03 changes- # # -words are unique now. Would sit and spin otherwise looking for a unique set # when randomizing. # -generated set is sorted now. Is easier on the eyes. # # 11/16/03 changes- # # -removed rand_set and now using random.shuffle. # -generated table has border-collapse set to collapse now. # -auto popup the print dialog. # # 08/28/08 changes- # # -added a Free space in the center print "Content-type: text/html" print "Link: ; rel=stylesheet" print "" import cgi, string, random, sys f = cgi.FieldStorage() # check for minimal stuff for e in 'swxy': if not f.has_key(e): print "

Error!

" print "Please fill in all the fields." sys.exit(1) sortWords=0 if f.has_key('sort'): sortWords=1 cardsperpage=3 if f.has_key('cpp'): cardsperpage = min(max(int(f['cpp'].value), 1), 5) x = min(max(int(f['x'].value), 1), 10) y = min(max(int(f['y'].value), 1), 10) freespace=0 if f.has_key('free'): # and both x and y are odd if x & 1 and y & 1: freespace=1 c = f.has_key('custom') and int(f['custom'].value) words = [] for l in string.split(f['w'].value, '\n'): for w in map(lambda x: string.strip(x), string.split(l, ',')): if len(w) and w not in words: words.append(w) if len(words) < x*y: print """

Error!

Not sufficient number of words were supplied... add some more or reduce the size of the grid. It's also possible that you reached this error becuz there are some duplicates in the list of words you provided- and on eliminating them we were left with a much smaller list of words, insufficient to generate a grid. """ sys.exit(1) print """ """ cards = min(max(1, int(f['s'].value)), 250) for i in range(cards): random.shuffle(words) set = words[:x*y] if sortWords: set.sort() if freespace: set[x*y/2] = "" if i>0 and i%cardsperpage == 0: print "
" print """
Name: ___________________________________
""" % x , t = len(set) for j in range(t): print '' % set[j] if not (j+1)%x: print '' if (j', print "
%s
Make your own cards at http://saksena.net/partygames/bingo/

" print ''