Skip to main content

After Hours

Fortune Cookie

Draw a developer fortune: dubious wisdom, a warning, a prediction, or a joke about Friday. The same package is a Python library and a command.

The PyPI name is lupaxa-fortune-cookie. The import path is lupaxa.fortune. The console scripts are fortune-cookie and lupaxa-fortune-cookie. lupaxa is a namespace package — there is no lupaxa/__init__.py.

Public names: Fortune, FortuneGenerator, generate_fortune, generate_fortunes, list_categories, Category, Mode, RiskLevel, FortuneError, InvalidOptionError, UnknownCategoryError, DatasetError, EmptyFortunePoolError, __version__, get_version().

Friday is a category you ask for. The tool does not look at the date, your repository, or the network. Oracle lines are entertainment. They never run commands.

Install

pip install lupaxa-fortune-cookie

Requires Python 3.10+. The standard library is enough.

CLI

fortune-cookie
fortune-cookie --category devops --count 3
fortune-cookie --dark
fortune-cookie --oracle --plain --no-numbers
fortune-cookie --seed 42
python -m lupaxa.fortune --category friday --plain

lupaxa-fortune-cookie is the same command. Decorative output is the default. --plain drops the emoji and headings. Lucky numbers are on unless you pass --no-numbers.

Flag Meaning
--category One ordinary category
--count How many fortunes to print (default 1)
--numbers Show lucky numbers (the default)
--no-numbers Hide lucky numbers
--dark Bleak fortunes
--corporate Jargon fortunes
--oracle A prediction, a risk, and an action
--plain No emoji or headings
--categories List ordinary categories and exit
--seed Repeat a result
--version Print lupaxa-fortune x.y.z and exit 0
-h, --help Show argparse help

Special modes cannot be combined with each other or with --category. --categories cannot be combined with generation options, including an explicit --count 1.

A seed builds one random.Random for that invocation. Turning numbers off skips a random draw, so the next fortune in a batch is not the one you would have seen with numbers on. The same seed can also change between Python releases, because it follows that version's random generator.

Result Stdout Exit
Success One fortune block per result 0
--version lupaxa-fortune x.y.z 0
Invalid arguments argparse diagnostic 2
Broken dataset lupaxa-fortune: error: ... 1
Interrupted error on stderr 130

Library

import random
from lupaxa.fortune import FortuneGenerator, generate_fortune

fortune = generate_fortune(category="devops", rng=random.Random(42))
print(fortune.text)
print(fortune.lucky_numbers)

oracle = generate_fortune(mode="oracle", include_numbers=False, rng=random.Random(42))
print(oracle.risk_level, oracle.recommended_action)

generator = FortuneGenerator(rng=random.Random(42))
results = generator.generate_many(count=3, category="code")

Pass your own random.Random when a result must repeat. The library does not call random.seed().

Call Return
generate_fortune() one standard fortune
generate_fortune(mode="oracle") one oracle fortune
generate_fortunes(3, category="code") three code fortunes
list_categories() the nine category names
Situation Result
Unknown category UnknownCategoryError
Bad mode, count, or combination InvalidOptionError
Bundled data is missing or wrong DatasetError

Development

make init
make python-install-dev
make python-check
The Lupaxa Project Footer

Metadata

Release files for lupaxa-fortune-cookie 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lupaxa-fortune-cookie 0.1.1
File Size Uploaded
lupaxa_fortune_cookie-0.1.1.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lupaxa-fortune-cookie 0.1.1
File Interpreter ABI Platform
lupaxa_fortune_cookie-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 53.6 kB

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page