Brazilian Championship Table in Terminal, ZZ Functions for Linux

Brazilian Championship Table in Terminal, ZZ Functions for Linux
Reading time: 3 min read
Link copied!

On a rainy Saturday, after hours of studying, I decided to take a break to check how Grêmio was doing in the Brazilian Championship. I looked at the standings and got the idea to bring the table to the terminal. Instead of opening the browser and navigating to the site, why not run a command and see everything right there, in the shell? I had already been creating small shortcuts for daily use, the previous week I made a .sh to switch between Wi-Fi networks -, so I took advantage of the momentum and played with ZZ Functions, that collection of utilities that solves a bunch of simple tasks. From there two functions were born: zzbrasileirao for Serie A and zzbrasileiraob for Serie B.

Below are the functions as I use in my environment. They do web scraping of the standings page and format the result with a colored header line and a legend explaining each column. The heavy work is done by $ZZWWWDUMP to “dump” the page in the terminal and sed to extract only the block that matters; echo -e comes in to make the visual more readable.

zzbrasileirao() {
# ----------------------------------------------------------------------------
# Shows the updated Brazilian Championship table, Serie A
# Author: Alexandre Brodt Fernandes <alexandre(a)programador.com>
# Site: http://www.xalexandre.com.br
# Version: 1.0
# Usage: zzbrasileirao
# ----------------------------------------------------------------------------
zzzz -z $1 zzbrasileirao && return
echo -e '[32m                             P  J       V       E       D       GP      GC      SG      % [m'
$ZZWWWDUMP 'http://globoesporte.globo.com/Esportes/Futebol/Classificacao/0,,ESP0-9827,00.html' | sed -n '55,74p'
echo -e '
   [32mP[moints [31m-[m [32mJ[mgames [31m-[m [32mV[mictories [31m-[m [32mE[mties [31m-[m [32mD[mefeats [31m-[m [32mG[moals [32mP[mro [31m-[m [32mG[moals [32mC[montra [31m-[m [32mS[maldo de [32mG[moals [31m-[m [32m%[mWin Rate'
}
zzbrasileiraob() {
# ----------------------------------------------------------------------------
# Shows the updated Brazilian Championship table, Serie B
# Author: Alexandre Brodt Fernandes <alexandre(a)programador.com>
# Site: http://www.xalexandre.com.br
# Version: 1.0
# Usage: zzbrasileiraob
# ----------------------------------------------------------------------------
zzzz -z $1 zzbrasileiraob && return
echo -e '[32m                  P  J       V       E       D       GP      GC      SG      % [m'
$ZZWWWDUMP 'http://globoesporte.globo.com/Esportes/Futebol/Classificacao/0,,ESP0-9828,00.html' | sed -n '54,73p'
echo -e '
   [32mP[moints [31m-[m [32mJ[mgames [31m-[m [32mV[mictories [31m-[m [32mE[mties [31m-[m [32mD[mefeats [31m-[m [32mG[moals [32mP[mro [31m-[m [32mG[moals [32mC[montra [31m-[m [32mS[maldo de [32mG[moals [31m-[m [32m%[mWin Rate'
}

ZZ Functions are created by Aurélio Marinho Jargas and are very worth installing. Download at http://funcoeszz.net, load in your .bashrc or .profile and ensure basic dependencies like lynx or wget. Once done, just paste the two functions in your preferences file and use when you want to check the standings without leaving the terminal.

In daily use the advantage is simple: speed to see the table, efficiency by not depending on the browser and freedom to adjust colors and format the way you like. Integration with any terminal makes it easy to run on servers or machines without graphical environment.

# View Serie A
$ zzbrasileirao

# View Serie B
$ zzbrasileiraob

Here’s the recommendation from someone who likes to solve things through the shell. ZZ Functions are simple and useful and still open space for you to create your own functions. Support free software and value what’s made here.