Skip to content

Scoreboard

nntrn edited this page Aug 6, 2024 · 4 revisions

Endpoints

Headers:
https://site.api.espn.com/apis/personalized/v2/scoreboard/header?league=nfl&sport=football

Download

curl -o scoreboard.json 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?limit=1000&dates=2023'

Functions

# file: nfl.jq

def walkobject(fn): walk(if type == "object" then fn else . end);

def nfl_espn_scoreboard:
  .events
  | map([.id,.status.type.name,.date,.shortName] as $game
  | .competitions[0].competitors
  | map([
      $game,
      .homeAway,
      .team.abbreviation,
      .winner? // "\(.winner)",
      (([.linescores[].value]? // ["--"])| join("-")),
      .score
    ] | flatten | join(","))
  )
  | flatten
  | join("\n")
  | "event_id,event_status,date,title,field,team,win,linescore,total\n" + .;

Examples

Recursively delete keys

jq 'include "walk"; walkobject(del(.links,.logo,.geoBroadcasts,.tickets,.broadcasts))' scoreboard.json 
Output
$ jq 'include "walk"; walkobject(del(.links,.logo,.geoBroadcasts,.tickets,.broadcasts)) | .events | first' scoreboard.json
{
  "id": "401437933",
  "uid": "s:20~l:28~e:401437933",
  "date": "2023-01-01T18:00Z",
  "name": "Arizona Cardinals at Atlanta Falcons",
  "shortName": "ARI @ ATL",
  "season": {
    "year": 2022,
    "type": 2,
    "slug": "regular-season"
  },
  "week": {
    "number": 17
  },
  "competitions": [
    {
      "id": "401437933",
      "uid": "s:20~l:28~e:401437933~c:401437933",
      "date": "2023-01-01T18:00Z",
      "attendance": 69269,
      "type": {
        "id": "1",
        "abbreviation": "STD"
      },
      "timeValid": true,
      "neutralSite": false,
      "conferenceCompetition": false,
      "playByPlayAvailable": true,
      "recent": false,
      "venue": {
        "id": "5348",
        "fullName": "Mercedes-Benz Stadium",
        "address": {
          "city": "Atlanta",
          "state": "GA"
        },
        "capacity": 75000,
        "indoor": true
      },
      "competitors": [
        {
          "id": "1",
          "uid": "s:20~l:28~t:1",
          "type": "team",
          "order": 0,
          "homeAway": "home",
          "winner": true,
          "team": {
            "id": "1",
            "uid": "s:20~l:28~t:1",
            "location": "Atlanta",
            "name": "Falcons",
            "abbreviation": "ATL",
            "displayName": "Atlanta Falcons",
            "shortDisplayName": "Falcons",
            "color": "000000",
            "alternateColor": "000000",
            "isActive": true,
            "venue": {
              "id": "5348"
            }
          },
          "score": "20",
          "linescores": [
            {
              "value": 0
            },
            {
              "value": 14
            },
            {
              "value": 0
            },
            {
              "value": 6
            }
          ],
          "statistics": [],
          "records": [
            {
              "name": "overall",
              "abbreviation": "Game",
              "type": "total",
              "summary": "6-10"
            },
            {
              "name": "Home",
              "type": "home",
              "summary": "5-3"
            },
            {
              "name": "Road",
              "type": "road",
              "summary": "1-7"
            }
          ]
        },
        {
          "id": "22",
          "uid": "s:20~l:28~t:22",
          "type": "team",
          "order": 1,
          "homeAway": "away",
          "winner": false,
          "team": {
            "id": "22",
            "uid": "s:20~l:28~t:22",
            "location": "Arizona",
            "name": "Cardinals",
            "abbreviation": "ARI",
            "displayName": "Arizona Cardinals",
            "shortDisplayName": "Cardinals",
            "color": "A40227",
            "alternateColor": "ffffff",
            "isActive": true,
            "venue": {
              "id": "3970"
            }
          },
          "score": "19",
          "linescores": [
            {
              "value": 3
            },
            {
              "value": 10
            },
            {
              "value": 3
            },
            {
              "value": 3
            }
          ],
          "statistics": [],
          "records": [
            {
              "name": "overall",
              "abbreviation": "Game",
              "type": "total",
              "summary": "4-12"
            },
            {
              "name": "Home",
              "type": "home",
              "summary": "1-8"
            },
            {
              "name": "Road",
              "type": "road",
              "summary": "3-4"
            }
          ]
        }
      ],
      "notes": [],
      "status": {
        "clock": 0,
        "displayClock": "0:00",
        "period": 4,
        "type": {
          "id": "3",
          "name": "STATUS_FINAL",
          "state": "post",
          "completed": true,
          "description": "Final",
          "detail": "Final",
          "shortDetail": "Final"
        }
      },
      "leaders": [
        {
          "name": "passingYards",
          "displayName": "Passing Leader",
          "shortDisplayName": "PASS",
          "abbreviation": "PYDS",
          "leaders": [
            {
              "displayValue": "222 YDS, 1 TD",
              "value": 222,
              "athlete": {
                "id": "3116188",
                "fullName": "David Blough",
                "displayName": "David Blough",
                "shortName": "D. Blough",
                "headshot": "https://a.espncdn.com/i/headshots/nfl/players/full/3116188.png",
                "jersey": "17",
                "position": {
                  "abbreviation": "QB"
                },
                "team": {
                  "id": "22"
                },
                "active": true
              },
              "team": {
                "id": "22"
              }
            }
          ]
        },
        {
          "name": "rushingYards",
          "displayName": "Rushing Leader",
          "shortDisplayName": "RUSH",
          "abbreviation": "RYDS",
          "leaders": [
            {
              "displayValue": "20 CAR, 83 YDS, 1 TD",
              "value": 83,
              "athlete": {
                "id": "4373626",
                "fullName": "Tyler Allgeier",
                "displayName": "Tyler Allgeier",
                "shortName": "T. Allgeier",
                "headshot": "https://a.espncdn.com/i/headshots/nfl/players/full/4373626.png",
                "jersey": "25",
                "position": {
                  "abbreviation": "RB"
                },
                "team": {
                  "id": "1"
                },
                "active": true
              },
              "team": {
                "id": "1"
              }
            }
          ]
        },
        {
          "name": "receivingYards",
          "displayName": "Receiving Leader",
          "shortDisplayName": "REC",
          "abbreviation": "RECYDS",
          "leaders": [
            {
              "displayValue": "7 REC, 78 YDS, 1 TD",
              "value": 78,
              "athlete": {
                "id": "4361307",
                "fullName": "Trey McBride",
                "displayName": "Trey McBride",
                "shortName": "T. McBride",
                "headshot": "https://a.espncdn.com/i/headshots/nfl/players/full/4361307.png",
                "jersey": "85",
                "position": {
                  "abbreviation": "TE"
                },
                "team": {
                  "id": "22"
                },
                "active": true
              },
              "team": {
                "id": "22"
              }
            }
          ]
        }
      ],
      "format": {
        "regulation": {
          "periods": 4
        }
      },
      "startDate": "2023-01-01T18:00Z",
      "headlines": [
        {
          "description": "— Desmond Ridder is still searching for his first touchdown pass three games into his career.",
          "type": "Recap",
          "shortLinkText": "Koo kicks short field goal, Falcons edge Arizona 20-19"
        }
      ]
    }
  ],
  "status": {
    "clock": 0,
    "displayClock": "0:00",
    "period": 4,
    "type": {
      "id": "3",
      "name": "STATUS_FINAL",
      "state": "post",
      "completed": true,
      "description": "Final",
      "detail": "Final",
      "shortDetail": "Final"
    }
  }
}

Format CSV linescore

jq -r 'include "nflutils"; nfl_espn_scoreboard' scoreboard.json | column -s, -t
Output
event_id   event_status      date               title       field  team  win    linescore    total
401437933  STATUS_FINAL      2023-01-01T18:00Z  ARI @ ATL   home   ATL   true   0-14-0-6     20
401437933  STATUS_FINAL      2023-01-01T18:00Z  ARI @ ATL   away   ARI   false  3-10-3-3     19
401437935  STATUS_FINAL      2023-01-01T18:00Z  CHI @ DET   home   DET   true   7-17-14-3    41
401437935  STATUS_FINAL      2023-01-01T18:00Z  CHI @ DET   away   CHI   false  10-0-0-0     10
401437937  STATUS_FINAL      2023-01-01T18:00Z  DEN @ KC    home   KC    true   6-7-0-14     27
401437937  STATUS_FINAL      2023-01-01T18:00Z  DEN @ KC    away   DEN   false  0-10-7-7     24
401437938  STATUS_FINAL      2023-01-01T18:00Z  MIA @ NE    home   NE    true   7-0-9-7      23
401437938  STATUS_FINAL      2023-01-01T18:00Z  MIA @ NE    away   MIA   false  0-7-7-7      21
401437939  STATUS_FINAL      2023-01-01T18:00Z  IND @ NYG   home   NYG   true   0-24-7-7     38
401437939  STATUS_FINAL      2023-01-01T18:00Z  IND @ NYG   away   IND   false  3-0-7-0      10
401437940  STATUS_FINAL      2023-01-01T18:00Z  NO @ PHI    home   PHI   false  0-0-10-0     10
401437940  STATUS_FINAL      2023-01-01T18:00Z  NO @ PHI    away   NO    true   7-6-0-7      20
401437941  STATUS_FINAL      2023-01-01T18:00Z  CAR @ TB    home   TB    true   0-10-0-20    30
401437941  STATUS_FINAL      2023-01-01T18:00Z  CAR @ TB    away   CAR   false  7-7-0-10     24
401437942  STATUS_FINAL      2023-01-01T18:00Z  CLE @ WSH   home   WSH   false  0-7-0-3      10
401437942  STATUS_FINAL      2023-01-01T18:00Z  CLE @ WSH   away   CLE   true   3-0-14-7     24
401437936  STATUS_FINAL      2023-01-01T18:00Z  JAX @ HOU   home   HOU   false  0-0-3-0      3
401437936  STATUS_FINAL      2023-01-01T18:00Z  JAX @ HOU   away   JAX   true   7-14-7-3     31
401437943  STATUS_FINAL      2023-01-01T21:05Z  SF @ LV     home   LV    false  10-7-7-10-0  34
401437943  STATUS_FINAL      2023-01-01T21:05Z  SF @ LV     away   SF    true   7-7-7-13-3   37
401437944  STATUS_FINAL      2023-01-01T21:05Z  NYJ @ SEA   home   SEA   true   10-7-3-3     23
401437944  STATUS_FINAL      2023-01-01T21:05Z  NYJ @ SEA   away   NYJ   false  3-3-0-0      6
401437945  STATUS_FINAL      2023-01-01T21:25Z  MIN @ GB    home   GB    true   14-13-0-14   41
401437945  STATUS_FINAL      2023-01-01T21:25Z  MIN @ GB    away   MIN   false  3-0-0-14     17
401437946  STATUS_FINAL      2023-01-01T21:25Z  LAR @ LAC   home   LAC   true   0-17-7-7     31
401437946  STATUS_FINAL      2023-01-01T21:25Z  LAR @ LAC   away   LAR   false  3-7-0-0      10
401437934  STATUS_FINAL      2023-01-02T01:20Z  PIT @ BAL   home   BAL   false  0-10-3-0     13
401437934  STATUS_FINAL      2023-01-02T01:20Z  PIT @ BAL   away   PIT   true   3-0-3-10     16
401437947  STATUS_CANCELED   2023-01-03T01:30Z  BUF @ CIN   home   CIN   null   --           0
401437947  STATUS_CANCELED   2023-01-03T01:30Z  BUF @ CIN   away   BUF   null   --           0
401437961  STATUS_FINAL      2023-01-07T21:30Z  KC @ LV     home   LV    false  3-0-3-7      13
401437961  STATUS_FINAL      2023-01-07T21:30Z  KC @ LV     away   KC    true   7-17-0-7     31
401437954  STATUS_FINAL      2023-01-08T01:15Z  TEN @ JAX   home   JAX   true   0-7-3-10     20
401437954  STATUS_FINAL      2023-01-08T01:15Z  TEN @ JAX   away   TEN   false  3-10-3-0     16
401437948  STATUS_FINAL      2023-01-08T18:00Z  TB @ ATL    home   ATL   true   10-0-10-10   30
401437948  STATUS_FINAL      2023-01-08T18:00Z  TB @ ATL    away   TB    false  7-10-0-0     17
401437949  STATUS_FINAL      2023-01-08T18:00Z  NE @ BUF    home   BUF   true   7-7-14-7     35
401437949  STATUS_FINAL      2023-01-08T18:00Z  NE @ BUF    away   NE    false  7-7-3-6      23
401437950  STATUS_FINAL      2023-01-08T18:00Z  MIN @ CHI   home   CHI   false  0-6-7-0      13
401437950  STATUS_FINAL      2023-01-08T18:00Z  MIN @ CHI   away   MIN   true   6-10-7-6     29
401437951  STATUS_FINAL      2023-01-08T18:00Z  BAL @ CIN   home   CIN   true   10-14-3-0    27
401437951  STATUS_FINAL      2023-01-08T18:00Z  BAL @ CIN   away   BAL   false  0-7-6-3      16
...
401547635  STATUS_SCHEDULED  2023-12-31T18:00Z  SF @ WSH    home   WSH   null   --           0
401547635  STATUS_SCHEDULED  2023-12-31T18:00Z  SF @ WSH    away   SF    null   --           0
401547629  STATUS_SCHEDULED  2023-12-31T18:00Z  CAR @ JAX   home   JAX   null   --           0
401547629  STATUS_SCHEDULED  2023-12-31T18:00Z  CAR @ JAX   away   CAR   null   --           0
401547625  STATUS_SCHEDULED  2023-12-31T18:00Z  MIA @ BAL   home   BAL   null   --           0
401547625  STATUS_SCHEDULED  2023-12-31T18:00Z  MIA @ BAL   away   MIA   null   --           0
401547631  STATUS_SCHEDULED  2023-12-31T18:00Z  TEN @ HOU   home   HOU   null   --           0
401547631  STATUS_SCHEDULED  2023-12-31T18:00Z  TEN @ HOU   away   TEN   null   --           0
401547636  STATUS_SCHEDULED  2023-12-31T21:05Z  PIT @ SEA   home   SEA   null   --           0
401547636  STATUS_SCHEDULED  2023-12-31T21:05Z  PIT @ SEA   away   PIT   null   --           0
401547630  STATUS_SCHEDULED  2023-12-31T21:25Z  LAC @ DEN   home   DEN   null   --           0
401547630  STATUS_SCHEDULED  2023-12-31T21:25Z  LAC @ DEN   away   LAC   null   --           0
401547235  STATUS_SCHEDULED  2023-12-31T21:25Z  CIN @ KC    home   KC    null   --           0
401547235  STATUS_SCHEDULED  2023-12-31T21:25Z  CIN @ KC    away   CIN   null   --           0
401547637  STATUS_SCHEDULED  2024-01-01T01:20Z  GB @ MIN    home   MIN   null   --           0
401547637  STATUS_SCHEDULED  2024-01-01T01:20Z  GB @ MIN    away   GB    null   --           0
Clone this wiki locally