Skip to content

Instantly share code, notes, and snippets.

@ntkog
Created March 19, 2020 15:05
Show Gist options
  • Save ntkog/5427c1900e0c9ac0c4ff21326704aa58 to your computer and use it in GitHub Desktop.
Save ntkog/5427c1900e0c9ac0c4ff21326704aa58 to your computer and use it in GitHub Desktop.
Bash function para descargarse el último informe de COVID-19 en España y convertir los datos a CSV
function covid19 () {
# Descargar informe
curl -sS -k $1 -O
PDF_FILENAME=`echo "$1" | cut -d'/' -f 10`
CSV_FILENAME=`echo $PDF_FILENAME | sed -r 's/\.pdf//'`
NOW=`date +%d_%m_%Y_%Hh`
# Convertir a texto
pdftotext -f 1 -l 1 -layout ${PDF_FILENAME}
# Convertir a CSV
cat Actualizacion_49_COVID-19.txt | sed '/^[[:space:]]*$/d' | sed '1,13d' | sed '22,$d' | sed -r 's/[[:space:]]{1,14}/ /g' | sed -r 's/^\s{1,5}//g' | sed -r 's/[[:space:]]{1,2}/;/g' | sed -e 's/Castilla-La;Mancha/Castilla La Mancha/' | sed -e 's/Castilla;y;León/Castilla y León/' | sed -e 's/C.;Valenciana/Comunidad Valenciana/' | sed -e 's/País;Vasco/País Vasco/' | sed -e 's/La;Rioja/La Rioja/' | sed -e 's/CCAA;Total;casos;IA;últimos;14;días;Ingreso;en;UCI;Fallecidos/CCAA;Total casos;IA últimos 14 días;UCI;Fallecidos/' | sed -r 's/\.//g' > "${CSV_FILENAME}_${NOW}.csv"
# Ya tienes tu csv con la actualización
}
@ntkog
Copy link
Author

ntkog commented Mar 19, 2020

Demo

asciicast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment