✅ What works now
- Script:
~/.local/bin/mlb-scores - Menu entry:
~/.local/share/applications/mlb-scores.desktop - No external dependencies (no
tabulate, no pip installs). - Pulls scores directly from the MLB Stats API.
- Output: plain text, one line per game, ends with Press Enter to close…
This version is minimal and reliable — no colors, no formatting, just today’s scores.
🛠 Install Steps (initial setup)
- Create the script:
# Restore MLB Scores basic script + menu entry
mkdir -p ~/.local/bin ~/.local/share/applications
cat > ~/.local/bin/mlb-scores <<'PY'
#!/usr/bin/env python3
import json, sys
from datetime import datetime
from urllib.request import urlopen, Request
from urllib.error import URLError
def fetch(url):
try:
with urlopen(Request(url, headers={"User-Agent":"mlb-scores-basic"}), timeout=15) as r:
return json.loads(r.read().decode("utf-8", errors="ignore"))
except URLError as e:
print(f"Network error: {e}")
return None
def main():
today = datetime.now().date().isoformat()
url = f"https://statsapi.mlb.com/api/v1/schedule?sportId=1&date={today}"
data = fetch(url)
print(f"MLB Games for {today}")
print("-" * 95)
if not data or not data.get("dates"):
print("No games found.")
input("Press Enter to close...")
return
games = data["dates"][0].get("games", [])
for g in games:
home = g["teams"]["home"]["team"]["name"]
away = g["teams"]["away"]["team"]["name"]
status = g.get("status", {}).get("detailedState", "—")
hs = g["teams"]["home"].get("score")
as_ = g["teams"]["away"].get("score")
if hs is not None and as_ is not None:
line = f"{away} at {home} — {status} | {away}: {as_} {home}: {hs}"
else:
line = f"{away} at {home} — {status}"
print(line)
print()
input("Press Enter to close...")
if __name__ == "__main__":
main()
PY
chmod +x ~/.local/bin/mlb-scores
cat > ~/.local/share/applications/mlb-scores.desktop <<'EOF'
[Desktop Entry]
Version=1.0
Type=Application
Name=MLB Scores
Comment=View MLB game scores (basic)
Exec=/home/$USER/.local/bin/mlb-scores
Icon=applications-sports
Terminal=true
Categories=Utility;Sports;
EOF
chmod +x ~/.local/share/applications/mlb-scores.desktop
update-desktop-database ~/.local/share/applications 2>/dev/null || true
xdg-desktop-menu forceupdate 2>/dev/null || true
echo "✅ MLB Scores restored. Launch it from your menu."