MLB Daily Scores
Fetches yesterday's game recap and today's upcoming game preview for the user's configured favourite MLB team. Includes spring training, regular season, postseason (Wild Card, Division Series, Championship Series, World Series), and exhibition games.
Data Source
Uses the free MLB Stats API (statsapi.mlb.com). No API key required.
Setup (one-time)
1. Install dependencies
Run the setup script to install the Python packages:
CODEBLOCK0
Or install manually:
CODEBLOCK1
2. Configure your team
Add this to ~/.openclaw/openclaw.json under skills.entries:
CODEBLOCK2
Valid team names — use the full official name:
Arizona Diamondbacks, Atlanta Braves, Baltimore Orioles, Boston Red Sox, Chicago Cubs, Chicago White Sox, Cincinnati Reds, Cleveland Guardians, Colorado Rockies, Detroit Tigers, Houston Astros, Kansas City Royals, Los Angeles Angels, Los Angeles Dodgers, Miami Marlins, Milwaukee Brewers, Minnesota Twins, New York Mets, New York Yankees, Oakland Athletics, Philadelphia Phillies, Pittsburgh Pirates, San Diego Padres, San Francisco Giants, Seattle Mariners, St. Louis Cardinals, Tampa Bay Rays, Texas Rangers, Toronto Blue Jays, Washington Nationals.
3. Set up the daily cron job
Ask me to set it up, or run manually:
CODEBLOCK3
Adjust the parameters:
- -
--cron "0 6 * * *" — time to run (6:00 AM); change to your preferred time - INLINECODE3 — your timezone
- INLINECODE4 — your preferred channel (discord, telegram, whatsapp, slack, etc.)
- INLINECODE5 — channel-specific target (channel ID, phone number, chat ID, etc.)
How to use
Automatic (cron)
Once the cron job is set up, the skill runs daily at your configured time and delivers the report to your channel.
On demand (slash command)
Send /mlb-daily-scores in any chat to get an immediate update.
Manual invocation
Ask me: "What happened in the Blue Jays game yesterday?" or "Give me today's MLB update"
Instructions for the agent
INLINECODE7 in these instructions refers to the directory containing this SKILL.md file. Determine this path from the location of this file (e.g., if this file is at /home/openclaw/.openclaw/workspace/skills/mlb-daily-scores/skills/mlb-daily-scores/SKILL.md, then {baseDir} is /home/openclaw/.openclaw/workspace/skills/mlb-daily-scores/skills/mlb-daily-scores).
When this skill is invoked (via cron, slash command, or user request):
- 1. Determine the base directory — find the directory where this SKILL.md and
fetch_mlb.py are located. Call this BASEDIR.
- 2. Read the user's config from
skills.entries.mlb-daily-scores.config:
-
team: the MLB team name (required)
-
timezone: IANA timezone string (optional, defaults to system timezone)
- 3. Run the fetch script using this EXACT command pattern (replacing BASEDIR with the actual path):
CODEBLOCK4
IMPORTANT: You MUST use the venv Python at BASEDIR/.venv/bin/python3. Do NOT use python, python3, or any other Python interpreter — the required packages are only installed inside the .venv virtual environment. Using any other Python will fail with import errors.
The --config flag tells the script to read team/timezone directly from ~/.openclaw/openclaw.json. No user values should be interpolated into the command string. This outputs JSON to stdout.
- 4. Parse the JSON output and check
has_data:
- If
has_data is
false and there's no error: it's off-season or a day off. Reply with
HEARTBEAT_OK (this suppresses the message in cron/heartbeat mode).
- If
has_data is
false and there's an
error field: report the error to the user.
- If
has_data is
true: format the report as described below.
- 5. Format the report using this structure (include
game_type from the JSON when it is not Regular Season):
CODEBLOCK5
- 6. Omit sections that have no data:
- No yesterday game → skip the recap section, note "No game yesterday"
- No today game → skip the preview section, note "No game scheduled today"
- No injuries → show the clean bill of health line
- 7. Keep the box score concise — include the linescore (innings R/H/E) but NOT the full box score text (it's too long for chat). Only include the full boxscore if the user explicitly asks for more detail.
- 8. Off-season handling — If neither yesterday nor today has a game and there are no injuries to report, respond with just
HEARTBEAT_OK so no message is delivered. The script covers all game types (spring training, regular season, postseason, exhibition), so true off-season gaps are only mid-November through late February.
MLB 每日比分
获取用户配置的最喜爱MLB球队的昨日比赛回顾和今日即将进行的比赛预览。涵盖春训、常规赛、季后赛(外卡赛、分区赛、冠军赛、世界大赛)以及表演赛。
数据来源
使用免费的 MLB Stats API(statsapi.mlb.com)。无需API密钥。
设置(一次性)
1. 安装依赖
运行设置脚本以安装Python包:
bash
macOS/Linux
bash {baseDir}/setup.sh
任意平台(包括Windows)
python {baseDir}/setup.py
或手动安装:
bash
pip install --user MLB-StatsAPI requests
2. 配置你的球队
将以下内容添加到 ~/.openclaw/openclaw.json 中的 skills.entries 下:
json5
{
skills: {
entries: {
mlb-daily-scores: {
enabled: true,
config: {
team: Toronto Blue Jays, // 你最喜爱的球队(全名)
timezone: America/Toronto, // 你的本地时区(IANA格式)
},
},
},
},
}
有效的球队名称 — 使用完整的官方名称:
亚利桑那响尾蛇队、亚特兰大勇士队、巴尔的摩金莺队、波士顿红袜队、芝加哥小熊队、芝加哥白袜队、辛辛那提红人队、克利夫兰守护者队、科罗拉多洛矶队、底特律老虎队、休斯顿太空人队、堪萨斯城皇家队、洛杉矶天使队、洛杉矶道奇队、迈阿密马林鱼队、密尔沃基酿酒人队、明尼苏达双城队、纽约大都会队、纽约洋基队、奥克兰运动家队、费城费城人队、匹兹堡海盗队、圣迭戈教士队、旧金山巨人队、西雅图水手队、圣路易斯红雀队、坦帕湾光芒队、德州游骑兵队、多伦多蓝鸟队、华盛顿国民队。
3. 设置每日定时任务
让我来设置,或手动运行:
bash
openclaw cron add \
--name MLB 每日比分 \
--cron 0 6 * \
--tz America/Toronto \
--session isolated \
--message 为我配置的球队运行 mlb-daily-scores 技能。使用 fetch_mlb.py 脚本,将结果格式化为美观的样式,并包含昨日回顾、今日预览以及任何伤病信息。 \
--announce \
--channel discord \
--to channel:YOURCHANNELID
调整参数:
- - --cron 0 6 * — 运行时间(早上6:00);更改为你偏好的时间
- --tz — 你的时区
- --channel — 你偏好的频道(discord、telegram、whatsapp、slack等)
- --to — 频道特定目标(频道ID、电话号码、聊天ID等)
如何使用
自动(定时任务)
一旦定时任务设置完成,该技能将在你配置的时间每天运行,并将报告发送到你的频道。
按需(斜杠命令)
在任何聊天中发送 /mlb-daily-scores 以获取即时更新。
手动调用
问我:蓝鸟队昨天的比赛发生了什么? 或 给我今天的MLB更新
给代理的说明
这些说明中的 {baseDir} 指包含此 SKILL.md 文件的目录。根据此文件的位置确定该路径(例如,如果此文件位于 /home/openclaw/.openclaw/workspace/skills/mlb-daily-scores/skills/mlb-daily-scores/SKILL.md,则 {baseDir} 为 /home/openclaw/.openclaw/workspace/skills/mlb-daily-scores/skills/mlb-daily-scores)。
当此技能被调用时(通过定时任务、斜杠命令或用户请求):
- 1. 确定基础目录 — 找到此 SKILL.md 和 fetch_mlb.py 所在的目录。将其称为 BASEDIR。
- 2. 读取用户配置 从 skills.entries.mlb-daily-scores.config 中:
- team:MLB球队名称(必需)
- timezone:IANA时区字符串(可选,默认为系统时区)
- 3. 运行获取脚本 使用以下精确命令模式(将 BASEDIR 替换为实际路径):
bash
BASEDIR/.venv/bin/python3 BASEDIR/fetch_mlb.py --config
重要: 你必须使用位于 BASEDIR/.venv/bin/python3 的 venv Python。不要使用 python、python3 或任何其他 Python 解释器——所需的包仅安装在 .venv 虚拟环境中。使用任何其他 Python 都会因导入错误而失败。
--config 标志告诉脚本直接从 ~/.openclaw/openclaw.json 读取球队/时区信息。不应将用户值插入到命令字符串中。这将输出 JSON 到标准输出。
- 4. 解析 JSON 输出 并检查 has_data:
- 如果 has
data 为 false 且没有错误:这是休赛期或休息日。回复 HEARTBEATOK(这将在定时任务/心跳模式下抑制消息)。
- 如果 has_data 为 false 且存在 error 字段:向用户报告错误。
- 如果 has_data 为 true:按如下所述格式化报告。
- 5. 格式化报告 使用以下结构(当不是常规赛时,从 JSON 中包含 game_type):
⚾ MLB 每日报告 — [球队名称]
📅 [今天的日期]
━━━━━━━━━━━━━━━━━━━━━━━
📊 昨日回顾 [game_type,例如 (春训) — 如果是常规赛则省略]
━━━━━━━━━━━━━━━━━━━━━━━
[比分行,例如:蓝鸟队 5, 洋基队 3]
胜投:[获胜投手]
败投:[失败投手]
救援:[救援投手,如果有]
逐局比分:
[来自API的逐局比分文本]
━━━━━━━━━━━━━━━━━━━━━━━
🔮 今日预览 [game_type,例如 (春训) — 如果是常规赛则省略]
━━━━━━━━━━━━━━━━━━━━━━━
[对手] @ [主队]
🕐 [本地时区的比赛时间]
🏟️ [场馆]
先发投手:
[客队]:[投手姓名] ([胜-负], [防御率] ERA)
[主队]:[投手姓名] ([胜-负], [防御率] ERA)
━━━━━━━━━━━━━━━━━━━━━━━
🏥 伤病报告
━━━━━━━━━━━━━━━━━━━━━━━
[对于每条伤病]:
• [球员姓名] ([位置]) — [伤病描述] [状态]
[如果没有伤病]:✅ 目前没有球员在伤病名单上。
- 6. 省略没有数据的部分:
- 没有昨日比赛 → 跳过回顾部分,注明昨日无比赛
- 没有今日比赛 → 跳过预览部分,注明今日无比赛安排
- 没有伤病 → 显示健康状态行
- 7. 保持比分板简洁 — 包含逐局比分(局数 R/H/E)但不要包含完整的比分板文本(对于聊天来说太长了)。仅在用户明确要求更多细节时才包含完整比分板。
- 8. 休赛期处理 — 如果昨天和今天都没有比赛 且 没有伤病需要报告,仅回复 HEARTBEAT_OK 以便不发送消息。该脚本涵盖所有比赛类型(春训、常规赛、季后赛、表演赛),因此真正的休赛期间隙仅出现在11月中旬至2月下旬。