tools / trivia / advice.py

trivia/advice.py

triviaworld● networkpython3

A random piece of advice (Advice Slip API, no API key).

Use when the user asks for a random piece of advice, 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/advice.py && chmod +x advice.py && ./advice.py --fraglet-help

3. Run it.

./advice.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:364e8075cc28bb20039912b22f7c8a29292c300a40b370f501d476507b43676d
receipt
add --receipt run.json to any run; receipt/attest.py verifies it against this hash without re-running.

Source

advice.py · 21 lines · sha256 364e8075cc28…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=A random piece of advice (Advice Slip API, no API key).
#: when=Use when the user asks for a random piece of advice, or a caption or meme needs one.
#: network=required
#: stdin=none
import sys
import json
import urllib.request

try:
    with urllib.request.urlopen("https://api.adviceslip.com/advice", timeout=15) as resp:
        data = json.load(resp)
except Exception as e:
    print(f"advice request failed: {e}", file=sys.stderr)
    sys.exit(1)

advice = (data.get("slip") or {}).get("advice")
if not advice:
    print("response missing advice", file=sys.stderr)
    sys.exit(1)
print(advice)