#!/usr/bin/python # TYPE:fun # DESC:Copycat (copydog, actually) version of the perl program cowsay, using a dog instead of a cow. # ARCH:dogsay.tar.gz import sys, getopt, re def errorize(s): print "ERROR: "+s sys.exit() def showhelp(): print """ dogsay.py is a Python version of cowsay, with dogs. Usage: dogsay.py [OPTIONS] STRING Example: dogsay.py -c -f cat Hello, dog! Options: -h Show this help -d Dead dog -s Scared dog -c Crazed dog -f Use the specified 'dog' file """ sys.exit() try: opt, arg = getopt.getopt(sys.argv[1:], "dshcf:") except getopt.GetoptError: errorize("Bad option. Run dogsay.py -h for help.") eyes = 'oo' tounge = ' ' thought = '.' dogtype = 'default' for o,a in opt: if o == '-h': showhelp() if o == '-d': eyes = 'xx' tounge = 'U' thought = 'o' elif o == '-s': eyes = 'OO' elif o == '-c': eyes = '\\/' thought = 'x' tounge = 'W' if o == '-f': dogtype = a say = ' '.join(arg) try: dog = open("dogs/"+dogtype+".dog").read() except IOError: errorize("No such file '%s.dog'" % dogtype) dog = re.sub("\$EYES", eyes, dog) dog = re.sub("\$TOUNGE", tounge, dog) dog = re.sub("\$THOUGHT", thought, dog) print ' '+'-'*(len(say)+2) print '< '+say+' >' print ' '+'-'*(len(say)+2) print dog