tools / trivia / cat-fact.py

trivia/cat-fact.py

triviaworld● networkpython3

A random cat fact (catfact.ninja, no API key).

Use when the user asks for a cat fact, or a caption or meme needs one.

Run it

1. Once per machine: install fragletc (Docker must already be running).

curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh

2. Fetch the tool and print its contract.

curl -fsSLO https://tools.ofthemachine.com/trivia/cat-fact.py && chmod +x cat-fact.py && ./cat-fact.py --fraglet-help

3. Run it.

./cat-fact.py

Parameters

nametyperequirementdescription
none

Outputs

stdout

Provenance

image
ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
reach
network=required — output depends on live external state; do not cache indefinitely.
procedure_hash
sha256:c2b1c14e8414a2d1edd2e81552a1de29d7a91c5a7bd7763aaed8d714359d8f31
receipt
add --receipt run.json to any run; receipt/attest.py verifies it against this hash without re-running.

Source

cat-fact.py · 22 lines · sha256 c2b1c14e8414…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=A random cat fact (catfact.ninja, no API key).
#: when=Use when the user asks for a cat fact, or a caption or meme needs one.
#: network=required
#: stdin=none
import sys
import json
import urllib.request

req = urllib.request.Request("https://catfact.ninja/fact", headers={"User-Agent": "ofthemachine-tools (https://github.com/ofthemachine/tools)"})
try:
    with urllib.request.urlopen(req, timeout=15) as resp:
        data = json.load(resp)
except Exception as e:
    print(f"cat fact request failed: {e}", file=sys.stderr)
    sys.exit(1)

fact = data.get("fact")
if not fact:
    print("response missing fact", file=sys.stderr)
    sys.exit(1)
print(fact)