Metadata-Version: 2.5
Name: led-ticker-football
Version: 0.5.0
Summary: Live NFL football scores widget for led-ticker, fed by ESPN's public scoreboard API (no key). Bundled team logos.
Project-URL: Homepage, https://docs.ledticker.dev
Project-URL: Documentation, https://docs.ledticker.dev/plugins/
Project-URL: Repository, https://github.com/JamesAwesome/led-ticker-plugins
Project-URL: Issues, https://github.com/JamesAwesome/led-ticker-plugins/issues
Project-URL: Changelog, https://github.com/JamesAwesome/led-ticker-plugins/releases
Author-email: James Awesome <james@morelli.nyc>
License-Expression: MIT
License-File: LICENSE
Keywords: football,led-matrix,led-ticker,led-ticker-plugin,live-scores,nfl,raspberry-pi,rgb-led-matrix,sports
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: System :: Hardware
Requires-Python: >=3.14
Requires-Dist: aiohttp>=3.12
Requires-Dist: led-ticker-core>=4.30
Requires-Dist: pillow>=13
Provides-Extra: dev
Requires-Dist: pre-commit>=4.0; extra == 'dev'
Requires-Dist: pyright>=1.1; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# led-ticker-football

Live NFL scores for [led-ticker](https://github.com/JamesAwesome/led-ticker). One `football.scores` widget shows a held scoreboard per game: score, quarter and clock, who has the ball, down and distance with the ball spot, timeouts remaining, the red zone lit in red, finals and the next scheduled game (with a `BYE WEEK` label when your team is off). On the bigsign and longboi each team carries its logo; the logos are bundled, so a sign never fetches an image. When a team you follow scores, the card plays a touchdown / field goal / safety celebration on its next turn in the rotation.

> **Disclosure:** the data comes from ESPN's public site API (`https://site.api.espn.com`, with `https://site.web.api.espn.com` as a fallback host). That feed is **unofficial and undocumented**. It needs no key and no account, but ESPN can change its shape or block clients at any time. The plugin parses it defensively: a bad or missing payload keeps the last good scores on the panel with a `STALE` label instead of crashing. This plugin is not affiliated with or endorsed by ESPN or the NFL. Team logos are the teams' marks, bundled for display on your own sign.

## Prerequisites

- A working [led-ticker](https://github.com/JamesAwesome/led-ticker) install (`led-ticker-core >= 4.30`).
- Internet access on the Pi (for the scores; the logos are already in the package).
- No API key.

## Install

This plugin auto-registers via the `led_ticker.plugins` entry point — once the package is installed, no `[plugins]` config change is needed.

**Into a containerized led-ticker (recommended):** add the package to your `config/requirements-plugins.txt` and rebuild:

```text
led-ticker-football
```

```bash
docker compose up -d --build
```

**Standalone (a venv that already has led-ticker):**

```bash
pip install led-ticker-football
```

Once installed, the `football.scores` widget (and the `:football.ball:` emoji, plus a logo emoji for every team) is available automatically.

### Team logo emoji

Every bundled logo is also an inline emoji, named after the team code in lower case: `:football.phi:`, `:football.dal:`, and so on. Use them in any text, such as a message, a section title or a two-row card:

```toml
[[playlist.section.widget]]
type = "message"
text = ":football.phi: PHILLY :football.phi:"
font = "Inter-Bold"
font_size = 28
```

On the bigsign and longboi a logo emoji is 32 px tall, cropped to the mark and up to 64 px wide, so a wordmark keeps its shape. On the smallsign it is an 8×8 sprite, which is a splash of team colour rather than a readable logo.

## Reading the board (if you don't follow football)

- **Quarter and clock** — four 15-minute quarters (`Q1`–`Q4`), `HALF` at halftime, `END Q3` between quarters, `OT` for overtime. The clock stops after most plays, so it moves in fits and starts.
- **Possession** — the team with the ball has a marker beside its score (a small triangle on the big panels, a dot on the smallsign).
- **Down & distance** — `3RD & 4` means the offense is on its third of four tries and still needs 4 yards. `1ST & GOAL`: within 10 yards of scoring. The **spot** (`PHI 38`) is where the ball is: on PHI's half of the field, 38 yards from PHI's goal line.
- **Red zone** — inside the opponent's 20-yard line. The down & distance and the possession marker turn red.
- **Timeouts** — three pips per team: lit while a timeout is left, dim once used.
- **Scores** — a touchdown is 6 (then +1 for the kick or +2 for a conversion), a field goal 3, a safety 2.

## Widget: `football.scores`

Add a `[[playlist.section.widget]]` block inside a playlist section of your `config/config.toml`:

```toml
[[playlist.section.widget]]
type = "football.scores"
teams = ["PHI", "NYG"]
timezone = "America/New_York"   # for kickoff times and the day boundary
```

`teams` is required (and must be non-empty) in the default `teams` mode. Everything else is optional tuning.

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `mode` | string | `"teams"` | `"teams"`, `"league"` or `"live"` — see [Modes](#modes). |
| `teams` | list of strings | `[]` | ESPN team codes, case-insensitive (`["PHI", "NYG"]`; note `WSH`, `LAR`, `JAX`, `LV`, `LAC`). Unknown codes are rejected by `led-ticker validate` with a close-match hint. In `league` / `live` modes it sets priority and which teams celebrate. |
| `max_games` | int | `8` | Cap on games per rotation in `league` / `live` modes. |
| `final_hold_hours` | int | `24` | How long a final stays in the rotation, measured from kickoff + 3 h 30 min (the feed carries no end time). A team plays once a week, so Sunday's result stays up through Monday by default; lower it to see the next game sooner. |
| `timezone` | string | `"America/New_York"` | IANA timezone for kickoff times (`TODAY`, `TONIGHT`, dates) and the day boundary. |
| `layout` | string | `"auto"` | `"auto"`, `"scoreboard"` or `"ticker"` — see [Layouts](#layouts). |
| `logos` | bool | `true` | Paint the bundled team logos on the bigsign and longboi. `false` paints the two-tone colour chips instead. Ignored on the smallsign, which never shows logos. |
| `celebration_flash` | bool | `false` | **Photosensitivity warning:** `true` opens every celebration with three full-panel flashes (about 5 per second) in the team's colour, which can trigger seizures in people with photosensitive epilepsy. Leave it `false` on any sign other people can see. With `false` the celebration is the detail card alone, for the full 4 s. `led-ticker` logs a warning at startup while it is on. |
| `update_interval` | int | `15` | How often, in seconds, this widget refreshes its cards and asks the shared source to poll. **Floored at 10** (ESPN caches for 10 s). While a game is live the source polls at most every 15 s, or at the lowest `update_interval` below that among the widgets sharing it. A value below 15 therefore speeds up live polling. A value above 15 slows this widget: its cards refresh only every `update_interval` seconds, and if no other widget polls more often, so does the source. Quieter periods poll more slowly regardless — see [Polling cadence](#polling-cadence). |
| `hold_time` | float | `0.0` | Minimum per-card hold in seconds (a number ≥ 0). The engine uses the larger of this and the section's `hold_time`. While a celebration is pending the card asks for 4 s per score **plus** the larger of this and 4 s for the board afterwards. |
| `padding` | int | `6` | Horizontal padding (logical px) after the line in the hi-res `layout = "ticker"` crawl (bigsign / longboi); it also counts toward whether the line fits and holds instead of scrolling. The scale-1 ticker, the held scoreboards and the celebration ignore it. A number >= 0 (a float is truncated to an int). |
| `demo` | bool | `false` | Render fixture games (a live 4th quarter with a touchdown celebration, halftime, an OT final, a next game, a bye week) with `PHI` and `NYG`, no network — for docs, gifs and hardware checks. The demo follows `celebration_flash` like a live game. The live game's touchdown celebrates on its first turn and again every third turn after (in `ticker` / `one_at_a_time` sections, about 12 s after each celebration ends) (set `teams = ["PHI"]` or similar: untracked scores only highlight the score). |
| `bg_color` | RGB list | none | Background fill behind the board, the ticker line and the scoring celebration, at every scale. |
| `font_color` | RGB list / string / table | unset | Override all text color. Scale-1 `layout = "ticker"` only. The smallsign board, the scoring celebration and the hi-res renderers paint their own palette. |
| `font` | string | core default | Font for the scale-1 ticker line. |
| `small_font` | string | `"5x8"` | Font for the scale-1 two-band scoreboard. |

### Modes

Football's unit is the **week**: every team plays once between Thursday and Monday, and ESPN's scoreboard returns the whole week in one payload.

- **`teams` (default)** — only games involving your `teams`, per team in config order: its live game; else a final still inside `final_hold_hours`; else its game later this week; else its next scheduled game from the team's schedule (also how a bye week shows: the next game, labelled `BYE WEEK`). Two tracked teams playing each other are one card, not two.
- **`league`** — every NFL game this week: your teams first, then other live games, then finals inside the hold, then upcoming games by kickoff (games with a `TBD` kickoff sort last). Capped by `max_games`.
- **`live`** — only games in progress, your teams first. Capped by `max_games`. With nothing live the widget has no stories, so the rotation skips it.

**Offseason:** when a tracked team has nothing scheduled at all, it contributes no story. A section holding only this widget in `teams` mode goes dark then; put something else in the section if that matters.

### Layouts

`layout = "auto"` resolves to `scoreboard` on all three reference signs.

- **Smallsign (160×16):** two 8-row bands, away on top. Each band: a 3-px brand chip, the abbreviation, the score, the possession dot, three timeout pips, and the down & distance on the band of the team with the ball (`3RD & 4`, cyan; red in the red zone). The quarter is right-aligned in the top band, with a small football icon just left of it so the card reads as football at a glance next to other sports; the clock is in the bottom band. The icon is left out when the top band is too full for it. The ball spot is omitted at this size (the `ticker` layout carries it).
- **Bigsign (256×64):** two held rows, one per team, with a dotted divider. Each row: the team's 28 px logo, abbreviation, a large white score, the possession triangle and the timeout pips. The right status column shows the quarter (amber), the clock (white) and `3RD & 4 · PHI 38` (cyan, red in the red zone; the spot is dropped first when the column is narrow).
- **Longboi (512×64):** a full scoreboard. The away team fills the left third (48 px logo at the edge, large abbreviation, pips beneath, huge score), the home team mirrors it on the right, and the centre holds the quarter, a large clock and the down & distance line. The possession triangle sits between the possessing team's score and the centre.
- **`ticker`:** one scrolling line per game using the same wording as the boards: `PHI 20 · NYG 17 · Q4 2:13 · NYG BALL 2ND & 7 · PHI 24 · TOL 1-2`.

Halftime, the end of a quarter and a delay show `HALF` / `END Q3` / `DELAY` with no clock and no situation. A final shows `FINAL` (plus `OT`) with the winner's score green. A next game shows the day (`TONIGHT`, `SUN NOV 1`, amber), the kickoff (`TBD` when the league hasn't set it) and the venue (dim), with the teams drawn per sign. Smallsign shows the football icon, then `PHI @ NYG` (or `VS` at a neutral site) in team colors, no chips and no records, with ` BYE` after it in a bye week. Bigsign shows `PHI 5-2 @ NYG 4-3` with each team's logo in front of its name (the records drop first when the line is too wide) and a small `NEXT GAME` / `BYE WEEK` / `PPD` label. Longboi shows both logos and abbreviations on their sides with the records, the team nicknames and that label, and no `@`. With `logos = false`, or for a team with no bundled logo, the bigsign and longboi paint that team's two-tone chip in the logo's place. Apart from `logos`, nothing on the physical boards is user-tunable (fixed palette).

### Scoring celebration

> **Photosensitivity warning:** with `celebration_flash = true`, each celebration opens with three full-panel flashes at about 5 per second in the team's colour. Flashing at that rate can trigger seizures in people with photosensitive epilepsy. The flash is off by default; leave it off on any sign in a shared or public space.

When a team in `teams` scores, that game's card plays a ~4 second celebration **the next time its turn comes around** — in a slideshow it never interrupts other content (scroll-mode sections are below). It shows the new score with the scoring team's number pulsing, the play (`JALEN HURTS 12 YD RUSH`), `+PAT` / `+2PT` once the try is in, and the quarter and clock, with the scoring team's logo at the left on the bigsign and longboi. Then the normal board for the rest of the hold. With `celebration_flash = true` it opens with three quick flashes of the panel in the scoring team's color with `TOUCHDOWN` / `FIELD GOAL` / `SAFETY` knocked out (see the warning above).

- A section's hold is **extended automatically** while a celebration is pending: the card asks for 4 s per queued score plus the larger of the widget's `hold_time` and 4 s for the board that follows.
- **The extra point folds in.** A touchdown's kick or two-point conversion never celebrates on its own: it updates the queued celebration's score and `+PAT` / `+2PT` label.
- Several scores between turns celebrate in order, up to 3 per turn; older ones are dropped.
- A score celebrates once per widget: replays on later rotations do not happen, and a celebration is only consumed once it actually reached the panel.
- In `mode = "ticker"` and `mode = "one_at_a_time"` sections, the celebration starts on the next frame the card is drawn and takes over the whole panel for its 4 s; the card itself resumes where its takeover began, while anything to its left keeps scrolling underneath, so up to about 80 px of a neighbour can pass unseen behind a celebration. On the bigsign and longboi the held scoreboard scrolls through such a section like a wide card. Known limit: a score that lands while the last card of a `ticker` section sits in its end-of-scroll hold is cut to the remainder of that hold (the section's `hold_time`, default 3 s) and resumes on the next pass.
- **First sight is a silent baseline.** Points already on the board when the widget first sees a game (boot, restart, hot reload, a game found mid-drive) do not celebrate.
- In `league` / `live` modes, scores by teams you do not track do not flash; the score is highlighted briefly and fades back to white. With an empty `teams` list nothing celebrates.
- A **score correction** (ESPN occasionally revises a score downward) quietly fixes the board and drops any queued celebration for it.

Scores are detected from the change in each team's total between polls; the scoreboard feed carries no play list. The play text comes from the feed's `lastPlay` when it is the scoring play, so a celebration can occasionally show the score with no play text.

### Polling cadence

All `football.scores` widgets in one process share a single source, so several widgets (or signs' worth of sections) do not multiply requests to ESPN.

- **Every 15 s** while any relevant game is live — faster if a widget sets a lower `update_interval` (floor 10 s), slower if every widget sharing the source sets a higher one (each widget polls only on its own `update_interval`).
- **Every minute** in the half hour around a relevant kickoff.
- **Every 5 minutes** when a relevant game is scheduled later today.
- **About hourly** otherwise (the rest of the week, the offseason).
- A tracked team's schedule (for the next game and the bye week) is fetched at most every 6 hours, and only when the team has no game left in the current week's payload.

**The clock does not tick between polls.** A football clock stops after most plays and the feed carries no "running" flag, so the board shows the clock exactly as last polled (hockey's locally ticking clock would be wrong more often than right here).

A failed request tries the fallback host, then keeps the last good games and marks every card `STALE` beside the state, never in place of it. Backoff starts at twice the interval and doubles, capped at four hours. A game that disappears from the feed keeps its last state — a final is never inferred from a game vanishing.

### Sign checks

The examples directory has separate demo and live configs for smallsign, bigsign and longboi:

- `config.football-demo.<sign>.toml` — fixture games, no network.
- `config.football-live.<sign>.toml` — live ESPN data for `PHI` and `NYG`.

Validate the chosen file with `led-ticker validate <path>` before starting the sign. Every file carries a `[web]` block (the webui sidecar restart-loops without one), and the longboi files carry the FM6126A panel tuning (`gpio_slowdown = 5`, `pwm_bits = 7`, `limit_refresh_rate_hz = 100`) — without it that panel flickers, which is the panel, not the widget. Check that the score, clock, possession marker and timeout pips have separated letters and every column stays inside the panel.

## Known limitations

- **Unofficial feed.** Undocumented and subject to change; see the disclosure above. ESPN has intermittently returned 403s to non-browser clients; the mirror host is tried automatically.
- **The live `situation` shape is hand-written.** No game was live when the plugin was built, so the possession / down & distance / timeouts parsing follows the community-documented shape and a captured preseason payload. If a field is absent or shaped differently the board simply omits it and everything else keeps working.
- **Scores can collapse.** Polls are 10–15 s apart, so a touchdown and its extra point usually arrive together (`+PAT` from the start). Two scores inside one poll (a touchdown and a field goal, say) celebrate once.
- **The sign runs ahead of your TV.** The feed is near real-time, broadcasts are delayed, so a score can appear on the panel before you see it on screen. There is no spoiler delay.
- **Logos are small.** The bigsign's logos are 28 px, so thin detail in a mark reads as a blob; the longboi's 48 px logos hold up better. Near-black pixels are dropped as invisible on the panel, so a mostly-black mark shows only its lighter parts.
- **Logo emoji on the smallsign are colour splashes.** At 8×8 a logo keeps its colours and rough shape, not its detail. A mostly-navy or mostly-black mark (the Capitals) is dim on any sign.
- NFL only.

## Data

ESPN site API, base URL `https://site.api.espn.com/apis/site/v2/sports/football/nfl` (mirror `https://site.web.api.espn.com`), no key. Endpoints: `/scoreboard` (the current week) and `/teams/{ABBR}/schedule` (next game, bye week). Community references: the [akeaswaran ESPN API gist](https://gist.github.com/akeaswaran/b48b02f1c94f873c6655e7129910fc3b), [pseudo-r/Public-ESPN-API](https://github.com/pseudo-r/Public-ESPN-API).

**Logos** are 64×64 PNGs for all 32 teams under `src/led_ticker_football/assets/logos/`, listed in `MANIFEST.txt` with their source URL and fetch date. They are refreshed by a person running `tools/fetch_logos.py` (never by CI or a sign); the plugin decodes each once per size and replays cached pixels.

## Development

```bash
uv sync --extra dev                                        # from the repo root
uv run pytest plugins/football --cov=plugins/football/src  # tests
uv run ruff check plugins/football && uv run pyright plugins/football/src
```
