Last active
April 14, 2022 16:33
-
-
Save D1360-64RC14/5f38151b81361fe67ef6b0334772fe53 to your computer and use it in GitHub Desktop.
Script responsável por fazer o Download de todas as imagens de radar recentes do SIMEPAR e criar um gif com as mesmas
This file contains hidden or 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 | |
download_image() { | |
# 1 -> Download image name | |
# 2 -> Output path | |
REF=http://www.simepar.br/ | |
URL=https://lb01.simepar.br/riak/pgw-radar/$1 | |
curl --silent --referer $REF --output $2 $URL | |
echo Downloaded $1! | |
} | |
wait_background() { | |
while [ $(jobs -pr | wc -l) -ne 0 ]; do | |
sleep 0.1 | |
done | |
} | |
EPOCH=$(date +%s) | |
FINAL_FILENAME=mosaic-$EPOCH.gif | |
TEMP_FOLDER=$(mktemp -d) | |
REFERER="http://www.simepar.br/" | |
echo Working on $TEMP_FOLDER | |
for N in {1..8}; do | |
# A ordem das imagens baixadas é inversa, | |
# precisando invertêlas para o convert | |
# ordenar-las corretamente. | |
INVERSE_N=$((9 - N)) | |
DOWNLOAD_IMG_NAME=product$N.jpeg | |
OUTPUT_IMG_NAME=product$INVERSE_N.jpeg | |
OUTPUT_PATH=$TEMP_FOLDER/$OUTPUT_IMG_NAME | |
# Download das imagens em segundo plano. | |
download_image $DOWNLOAD_IMG_NAME $OUTPUT_PATH & | |
done | |
# Espera os Downloads terminarem | |
wait_background | |
echo Generating gif... | |
convert -delay 30 -loop 0 $TEMP_FOLDER/*.jpeg $TEMP_FOLDER/$FINAL_FILENAME | |
echo Done! Saved in /tmp/$FINAL_FILENAME | |
# Copia a imagem pro diretório temporário | |
# e à abre no visualizador de imagens do GNOME. | |
cp $TEMP_FOLDER/$FINAL_FILENAME /tmp | |
eog /tmp/$FINAL_FILENAME & | |
rm -rf $TEMP_FOLDER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment