# # from Joe Strout's Python Tidbits (http://www.strout.net/python/) # def append(w,suffix): from string import uppercase, upper, lower if not w: return suffix elif w[-1] in uppercase: return w + upper(suffix) else: return w + lower(suffix) import string s = SampleBlock.NameEntry[:] out = '' for word in string.splitfields(s,' '): if word: # check for punctuation p = 0 while word[p-1] not in string.uppercase+string.lowercase: p = p-1 if p: punc = word[p:] word = word[:p] else: punc = '' # and pre-punc (e.g., parentheses) p = 0 while word[p] not in string.uppercase+string.lowercase: p = p+1 prepunc = word[:p] word = word[p:] # note capitalization if word[0] in string.uppercase: caps = 1 else: caps = 0 # remove up to the first vowel to make suffix p = 0 while p < len(word) and word[p] not in "aoeuiyAOEUIY": p = p+1 if not p: word = append( word, "yay" ) else: word = append( word[p:], word[:p]+"ay") # recapitalize, as appropriate if caps: word = string.upper(word[0]) + word[1:] # restore any punctuation word = prepunc + word + punc out = out + ' ' + word SampleBlock.CodeNameEntry = string.strip(out) Fortunes = ['You will have a long and fruitful life with GNUe.', 'GNUe will solve your next IT problem.', 'Why you not use GNUe before now?', 'You will fall in love with a tall, dark GNUe form.', 'Joy will overcome your new life with GNUe.', 'You will live a free life with GNUe tools', 'Move slowly but surely to success with GNUe.', 'Others are drawn to your GNUe tools.', 'You have a magnetic personality with GNUe forms.', 'Use GNUe and you will notice the extraordinary in the ordinary.'] if len(SampleBlock.YearEntry): try: val = 'Confucius say, "%s"'%Fortunes[int(str(SampleBlock.YearEntry)[-1:])] except ValueError: val = "Please enter a valid birth year first." else: val = "Please enter a valid birth year first." SampleBlock.FortuneEntry = val