Last active
September 29, 2016 13:44
-
-
Save gmarcos87/c9a059c5a64c6680e98d2b8c429fb44a to your computer and use it in GitHub Desktop.
Script en bash para descargar y buscar en los Boletines oficiales de la provincia de Córdoba, Argentina. Es necesario hacerlo ejecutable con "chmod a+rwx boletin.sh" y se puede pasar el parámetro de fecha "./boletin.sh DDMMYYYY". Si no se envia el atributo de fecha toma la del momento de la ejecución.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
declare -a URLS | |
if [[ -n "$1" ]]; then | |
fecha=$1 | |
else | |
fecha=`date +%d%m%Y` | |
fi | |
day=${fecha:0:2} | |
mon=${fecha:2:2} | |
year=${fecha:4:4} | |
cba_url=http://boletinoficial.cba.gov.ar/wp-content/4p96humuzp | |
palabras="jose de la quintana\|audiencia\|san isidro\|sol de venus" | |
function url_pdf() | |
{ | |
x=1 | |
while [ $x -le 5 ] | |
do | |
URLS+=("${cba_url}/${year}/${mon}/${x}_Secc_${fecha}.pdf") | |
x=$((x+1)) | |
done | |
( IFS=$'\n'; echo "${URLS[*]}" ) | |
} | |
function download() | |
{ | |
mkdir -p pdf/$fecha | |
( eval "wget -N ${URLS[*]} -P pdf/${fecha}/" ) | |
} | |
function buscar() | |
{ | |
find ./pdf/$fecha -iname '*.pdf' | while read filename | |
do | |
echo -e "\033[34;1m === PDF:\033[33;1m $filename\033[0m" | |
(eval "pdftotext \"${filename}\" - | grep --with-filename --label=\"${filename}\" --color -i -w \"${palabras}\";") | |
done | |
} | |
#Ejecuto las funciones en secuencia | |
echo -e "\033[33;1m Buscando las direcciones para los boletines del día ${day}/${mon}/${year}\033[0m" | |
url_pdf | |
echo -e "\033[33;1m Descargando los boletines\033[0m" | |
download | |
echo -e "\033[33;1m Descarga completa, buscando las palabras seleccionadas\033[0m" | |
buscar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment