trivia/on-this-day.py
Notable events that happened on a month and day in history, from Wikipedia's "On this day" feed (Wikimedia API, no key). One "YEAR<TAB>text" line per event, most recent first, count-limited, so a briefing can pick the one that rhymes with today.
Use when the user asks what happened on this day in history, or a newspaper, briefing, or caption wants an anniversary for a given date.
- the file
- trivia/on-this-day.py
- its skill
- trivia/SKILL.md (the whole trivia pack)
- as knowledge
- okf/trivia/on-this-day.md
- on GitHub
- trivia/on-this-day.py ↗
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/on-this-day.py && chmod +x on-this-day.py && ./on-this-day.py --fraglet-help
3. Run it.
./on-this-day.py -p month="<month>" -p day="<day>" [-p count=8]
Parameters
| name | type | requirement | description |
|---|---|---|---|
| month | string | required | Month as a number, 1-12 |
| day | string | required | Day of the month, 1-31 |
| count | string | default 8 | How many events to print |
Outputs
stdout
Provenance
- image
- ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
- reach
network=required— output depends on live external state; do not cache indefinitely.- procedure_hash
- sha256:28ecb7ef4d664cc658e7e4db5fa12acfe5b27e72002e5662e07b83cbfbb38115
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
on-this-day.py · 31 lines · sha256 28ecb7ef4d66…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=Notable events that happened on a month and day in history, from Wikipedia's "On this day" feed (Wikimedia API, no key). One "YEAR<TAB>text" line per event, most recent first, count-limited, so a briefing can pick the one that rhymes with today.
#: when=Use when the user asks what happened on this day in history, or a newspaper, briefing, or caption wants an anniversary for a given date.
#: network=required
#: stdin=none
#: param=month:required:d=Month as a number, 1-12
#: param=day:required:d=Day of the month, 1-31
#: param=count:default=8:d=How many events to print
import json
import os
import sys
import urllib.request
try:
month, day, count = int(os.environ["MONTH"]), int(os.environ["DAY"]), int(os.environ["COUNT"])
except ValueError as e:
print(f"bad parameter: {e}", file=sys.stderr)
sys.exit(2)
url = f"https://api.wikimedia.org/feed/v1/wikipedia/en/onthisday/events/{month:02d}/{day:02d}"
req = urllib.request.Request(url, headers={"User-Agent": "ofthemachine-tools (https://github.com/ofthemachine/tools)"})
try:
with urllib.request.urlopen(req, timeout=20) as resp:
events = json.load(resp).get("events") or []
except Exception as e:
print(f"on-this-day request failed: {e}", file=sys.stderr)
sys.exit(1)
events.sort(key=lambda ev: ev.get("year", 0), reverse=True)
for ev in events[:count]:
print(f"{ev.get('year', '?')}\t{ev.get('text', '').strip()}")