Last active
September 21, 2016 13:42
-
-
Save dvdvck/05ac5a155afc8dc8800b5bed4d04425e to your computer and use it in GitHub Desktop.
Obtiene las imagenes comprimidas por tinyfy.com, la url es obtenida de la respuesta del API
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
#!/usr/bin/env bash | |
#Usa el metadato txt para traer la imagen que se ha convertido | |
#Su ejecucion es en CWD de ~/t6e/issemym/img-proc | |
unit=${1?Falta unidad medica} | |
dest=$PWD | |
if [ -z ${API:+x} ]; then echo "falta API"; exit 1; fi | |
# setup log file | |
#logfile=$dest/pull$(date +%F_%T).log | |
logfile=$dest/pull.log | |
exec &> >(tee -a $logfile) | |
while IFS= read -r -d '' i; do | |
filename=${i##*/} | |
name=${filename%.*} | |
path=${i%/*} | |
source="$dest/$i" | |
output="$dest/$path/$name.jpg" | |
if [ ! -e "$output" ]; then | |
url=$(jq -r .output.url "$source") | |
if [[ ! $? == 0 || -z $url || ! $url =~ ^https.+ ]]; then | |
echo "ERROR en $filename: url: $url" | |
continue | |
fi | |
echo "Procesando $filename - $url" | |
#continue | |
curl -Ss "$url" -u api:$API -o "$output" | |
last=$? | |
if [ "$last" -ne 0 ]; then | |
echo "curl error $last on file $filename" | |
exit 2 | |
fi | |
fi | |
done < <(find "$unit/Digital/Anexo C/" -name *.txt -print0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment