Posts List

🚢Gee Dangit

💻 OCC Day 6 - Using curl, jq, and groff to make a table of baseball standings

I adapted a script I'd written for NBA (basketball) standings to work for MLB (baseball) standings. It uses groff to makes tables that look like this:


+---------------------------+
|   AMERICAN LEAGUE WEST    |
+-----------+------+--------+
|   TEAM    | WINS | LOSSES |
+-----------+------+--------+
|  Rangers  |  48  |   46   |
+-----------+------+--------+
| Mariners  |  47  |   48   |
+-----------+------+--------+
|  Astros   |  46  |   50   |
+-----------+------+--------+
| Athletics |  41  |   53   |
+-----------+------+--------+
|  Angels   |  38  |   57   |
+-----------+------+--------+
            

The script uses curl to grab some JSON data from statsapi.mlb.com and then uses jq to sort the teams in the American League West division, then we create a table definition and pass that to groff with the tbl preprocessor switch (-t) and type ascii switch (-Tascii).

Note: script only tested on Debian 13/Bash 5.2 so far...