Package fortune
[frames] | no frames]

Package fortune

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

Usage:

   fortune [OPTIONS] /path/to/fortunes

   OPTIONS

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

If you omit the path, fortune looks at the FORTUNE_FILE environment variable. If that environment variable 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:

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

License and Copyright Info

Copyright (c) 2008 Brian M. Clapper

This is free software, released under the following BSD-like license:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED AS IS AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Functions
str
get_random_fortune(fortuneFile)
Get a random fortune from the specified file.
 
make_fortune_data_file(fortuneFile, quiet=False)
Create or update the data file for a fortune cookie file.
 
main()
Main program.
Function Details

get_random_fortune(fortuneFile)

 

Get a random fortune from the specified file. Barfs if the corresponding .dat file isn't present.

Parameters:
  • fortuneFile (str) - path to file containing fortune cookies
Returns: str
the random fortune

make_fortune_data_file(fortuneFile, quiet=False)

 

Create or update the data file for a fortune cookie file.

Parameters:
  • fortuneFile (str) - path to file containing fortune cookies
  • quiet (boolean) - If True