Skip to main content

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


fortune [OPTIONS] /path/to/fortunes


-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.

# 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
    -- Fred Brooks, Jr.
A man is not old until regrets take the place of dreams.
    -- John Barrymore

# Generating a Random Fortune

Just run:

fortune /path/to/fortunes

If your FORTUNE_FILE environment variable is set, you can run it as


# 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.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fortune-1.1.0.tar.gz (4.4 kB view hashes)

Uploaded source

Built Distribution

fortune-1.1.0-py2.py3-none-any.whl (5.9 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page