Python version of old BSD Unix fortune program
Project description
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 -h, --help Show usage and exit. -u, --update Update the index file. -q, --quiet When updating the index file, do so quietly. -V, --version Show version and exit.
If you omit the path, fortune looks at the FORTUNE_FILE environment variable. If that environment variable isn’t set, fortune aborts.
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 I{strfile}(8) command to generate the index. With I{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.
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:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
The end-user documentation included with the redistribution, if any, must include the following acknowlegement:
This product includes software developed by Brian M. Clapper (bmc@clapper.org, http://www.clapper.org/bmc/). That software is copyright (c) 2008 Brian M. Clapper.
Alternately, this acknowlegement may appear in the software itself, if and wherever such third-party acknowlegements normally appear.
THIS SOFTWARE IS PROVIDED B{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.