[logo] Python Fortune Program

Download

To obtain my PGP/GnuPG key, see these instructions.

Documentation

Back to software page.

Introduction

fortune is a stripped-down implementation of the classic BSD Unix fortune command. It combines the capabilities of the strfile command (which produces the fortune index file) and the fortune command (which displays a random fortune). It reads the traditional fortune program's text file format.

Usage

fortune [OPTIONS] /path/to/fortunes

OPTIONS

-u, --update Update the index file.
-q, --quiet When updating the index file, do so quietly.

If the fortune file is omitted, fortune looks for the path in the FORTUNE_FILE environment variable. If FORTUNE_FILE isn't set, fortune aborts.

Fortune Cookie File Format

A fortune cookie file is a text file full of quotes. The format is simple: The file consists of paragraphs separated by lines containing a single '%' character. For example:

A little caution outflanks a large cavalry.
        -- Bismarck
%
A little retrospection shows that although many fine, useful software
systems have been designed by committees and built as part of multipart
projects, those software systems that have excited passionate fans are
those that are the products of one or a few designing minds, great
designers. Consider Unix, APL, Pascal, Modula, the Smalltalk interface,
even Fortran; and contrast them with Cobol, PL/I, Algol, MVS/370, and
MS-DOS.
        -- Fred Brooks, Jr.
%
A man is not old until regrets take the place of dreams.
        -- John Barrymore

The Index File

For efficiency and speed, fortune uses an index file to store the offsets and lengths of every fortune in the text fortune file. So, before you can use fortune to read a random fortune, you have to generate the data file. With the traditional BSD fortune program, you used the strfile(8) command to generate the index. With this fortune program, however, you simply pass a special argument to the fortune command:

fortune -u /path/to/fortunes

That command will generate a binary /path/to/fortunes.dat file that contains the index. You should run fortune -u whenever you change the text fortune file.

Generating a Random Fortune

Once you have an index file, you can generate a random fortune simply by running the fortune utility with the path to your text fortunes file:

fortune /path/to/fortunes

Differences

This version of fortune does not provide some of the more advanced capabilities of the original BSD program. For instance, it lacks:

  • the ability to mark offensive and inoffensive fortunes
  • the ability to separate long and short quotes
  • the ability to print all fortunes matching a regular expression

It does, however, provide the most important function: The ability to display a random quote from a set of quotes.

Installation

The usual:

  1. Unpack the tarball or Zip file.
  2. Change your directory to the resulting fortune-0.2 directory.
  3. Run: python setup.py install
This library is also available on PyPI. If you have Easy Install installed, you can install this package with one command (usually as root):
easy_install fortune

Author

Brian M. Clapper, <bmc @ clapper . org>

Copyright

© 2008 Brian M. Clapper

License

BSD-style license. See accompanying LICENSE file.

$Id: index.html,v 1.7 2005/05/20 14:37:58 bmc Exp $