#!/usr/bin/bash ##### # # weather - Downloads weather maps # # Usage: weather [ pause | resume ] [ show | unshow ] [ clean ] # # $RCSfile: weather,v $ # $Revision: 1.15 $ # $Date: 2006/03/20 15:01:54 $ # ##### function get_it { file=$1 url=$2 /usr/bin/wget -q --no-cache -T 15 -t 2 -O $file $url >>weather.log 2>&1 if [[ ! -s $file ]]; then rm -f $file echo "Failure getting $file: $url" >>weather.log date >>weather.log exit 1 fi } if [[ $LOGNAME == 'Jerry' ]]; then cd /y else cd /x fi if [[ ! -d Weather ]]; then mkdir Weather fi cd Weather # Pause in weather processing if [[ -n $1 ]]; then if [[ $1 == 'pause' ]]; then touch PAUSE echo 'Weather paused' exit 0 elif [[ $1 == 'resume' ]]; then rm -f PAUSE echo 'Weather resumed' elif [[ $1 == 'show' ]]; then weatherx exit 0 elif [[ $1 == 'unshow' ]]; then kill `cat /var/run/weatherx.pid` rm -f /var/run/weatherx.pid exit 0 elif [[ $1 == 'clean' ]]; then echo 'Cleaning...' today=`date +%m%d` for dir in map rsm rlg cur sat vis; do keep="$dir/$today" for x in $dir/????; do if [[ $x != $keep ]]; then rm -fr $x fi done done echo 'Done' exit 0 else echo "Unknown arg: $1" exit 1 fi fi if [[ -f PAUSE ]]; then exit 0 # Paused fi # Current weather get_it map.jpg http://image.weather.com/images/maps/current/curwx_720x486.jpg get_it rsm.jpg http://image.weather.com/web/radar/us_phl_ultraradar_large_usen.jpg get_it rlg.jpg http://image.weather.com/web/radar/us_har_closeradar_large_usen.jpg get_it cur.jpg http://image.weather.com/images/maps/current/cur_ec_720x486.jpg get_it sat.jpg http://image.weather.com/images/sat/regions/east_cen_sat_720x486.jpg get_it vis.jpg http://image.weather.com/images/sat/regions/ec_vis_sat_720x486.jpg today=`date +%m%d` now=`date +%H%M` for x in map rsm rlg cur sat vis; do if [[ ! -f $x.jpg ]]; then continue fi if [[ ! -s $x.jpg ]]; then rm -f $x.jpg continue fi if [[ ! -d $x/$today ]]; then mkdir -p $x/$today fi if [[ -f $x/.last ]]; then if [[ -f `cat $x/.last` ]]; then if diff -q `cat $x/.last` $x.jpg >/dev/null; then rm -f $x.jpg fi fi fi if [[ -f $x.jpg ]]; then echo $x/$today/$now.jpg >$x/.last mv $x.jpg $x/$today/$now.jpg fi done # Forecasts if [[ -d fore ]]; then rm -f fore/*.jpg else mkdir -p fore fi day=`date +%w` if [[ $day -ne 0 ]]; then day=$(( 7 - $day )) fi get_it fore/${day}_sun.jpg http://image.weather.com/images/maps/forecast/trend7_720x486.jpg day=$(( $day + 1 )) if [[ $day -eq 7 ]]; then day=0 fi get_it fore/${day}_mon.jpg http://image.weather.com/images/maps/forecast/fore1_720x486.jpg day=$(( $day + 1 )) if [[ $day -eq 7 ]]; then day=0 fi get_it fore/${day}_tue.jpg http://image.weather.com/images/maps/forecast/fore2_720x486.jpg day=$(( $day + 1 )) if [[ $day -eq 7 ]]; then day=0 fi get_it fore/${day}_wed.jpg http://image.weather.com/images/maps/forecast/fore3_720x486.jpg day=$(( $day + 1 )) if [[ $day -eq 7 ]]; then day=0 fi get_it fore/${day}_thu.jpg http://image.weather.com/images/maps/forecast/fore4_720x486.jpg day=$(( $day + 1 )) if [[ $day -eq 7 ]]; then day=0 fi get_it fore/${day}_fri.jpg http://image.weather.com/images/maps/forecast/fore5_720x486.jpg day=$(( $day + 1 )) if [[ $day -eq 7 ]]; then day=0 fi get_it fore/${day}_sat.jpg http://image.weather.com/images/maps/forecast/trend6_720x486.jpg get_it fore/_0_cur.jpg http://image.weather.com/images/maps/current/curwx_720x486.jpg if [[ $now < '0400' || $now > '1900' ]]; then get_it fore/_1_am.jpg http://image.weather.com/images/maps/forecast/amfcst_720x486.jpg get_it fore/_2_mid.jpg http://image.weather.com/images/maps/forecast/midfcst_720x486.jpg get_it fore/_3_pm.jpg http://image.weather.com/images/maps/forecast/pmfcst_720x486.jpg elif [[ $now < '1300' ]]; then get_it fore/_3_am.jpg http://image.weather.com/images/maps/forecast/amfcst_720x486.jpg get_it fore/_1_mid.jpg http://image.weather.com/images/maps/forecast/midfcst_720x486.jpg get_it fore/_2_pm.jpg http://image.weather.com/images/maps/forecast/pmfcst_720x486.jpg else get_it fore/_2_am.jpg http://image.weather.com/images/maps/forecast/amfcst_720x486.jpg get_it fore/_3_mid.jpg http://image.weather.com/images/maps/forecast/midfcst_720x486.jpg get_it fore/_1_pm.jpg http://image.weather.com/images/maps/forecast/pmfcst_720x486.jpg fi if [[ -s weather.log ]]; then date >>weather.log else rm weather.log fi # EOF