Skip to content

Instantly share code, notes, and snippets.

@blast-hardcheese
Forked from lubosz/weather.sh
Last active August 29, 2015 14:19
Show Gist options
  • Save blast-hardcheese/fc4d22ecdcfe2417a742 to your computer and use it in GitHub Desktop.
Save blast-hardcheese/fc4d22ecdcfe2417a742 to your computer and use it in GitHub Desktop.
#!/bin/sh
DOWNLOAD_DIR="$HOME/Downloads/weather"
REGION=txgulf
die() {
ec=$1
shift
echo $@ >&2
exit $ec
}
# make download dir if not available
if [ ! -d "$DOWNLOAD_DIR" ]; then
mkdir -p "$DOWNLOAD_DIR" || die 1 "Unable to create $DOWNLOAD_DIR"
fi
# set loop counter
COUNTER=0
# remove old files
rm -rf "$DOWNLOAD_DIR"/*.gif
rm -rf "$DOWNLOAD_DIR"/*.txt
rm -rf "$DOWNLOAD_DIR"/*.png
# replace URL with your region
wget -O "$DOWNLOAD_DIR/map.gif" "http://archive.wfaa.com/weather/images/core/animated-loops/comp/880x495/${REGION}_anim.gif"
# expand gif and convert to png
convert -coalesce "$DOWNLOAD_DIR"/map.gif "$DOWNLOAD_DIR"/map.png || die 2 "Unable to find convert. Install imagemagick"
# display extracted images as ASCII
for i in "$DOWNLOAD_DIR"/map-*.png; do
img2txt -W 75 -H 30 $i > $i.txt || die 3 "Unable to find img2txt. Install caca-utils"
done
clear
echo # Compensate for cursor movement oddity
while [ $COUNTER -lt 5 ] ; do
for i in "$DOWNLOAD_DIR"/map-*.txt; do
cat $i
lines=$(cat $i | wc -l)
lines=$((lines+1)) # img2txt seems to lack trailing newline
sleep 0.5
echo -e "\033[${lines}A"
done
let COUNTER=COUNTER+1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment