A Newbie's Scripts for Cygwin 1

March 10th, 2007 § 0

国家地理网站下载每日图片


#!/usr/bin/bash
# picngs: Download today’s picture from National Geographics website
# Michael.Fantasia@Gmail.com

BADDATE=66
WEBFAILURE=67
SEDFAILURE=68

picdir=${2:-d:/Pictures/经典照片}

cd ~/temp
rm -f 00

if [ $# -eq 0 ]
then
mfdate=$(date +%Y.%m.%d)
wget -q http://lava.nationalgeographic.com/pod/ -O 00
else
if date -d $1 +%Y%m%d
then
mfdate=$(date -d $1 +%Y.%m.%d)
wget -q http://lava.nationalgeographic.com/cgi-bin/pod/wallpaper.cgi?day=$(date -d $1 +%d)&month=$(date -d $1 +%m)&year=$(date -d $1 +%y) -O 00
else
echo Unknown date format. >&2
exit $BADDATE
fi
fi

if [ $? -ne 0 ]
then
echo Error in downloading picture. >&2
exit $WEBFAILURE
fi

findname=$(sed -n s/.*\(sm\|lg\)_\([^>]*jpg\).*/lg_\2/p 00 | sed -n 1 p)

if [ -z "findname" ]
then
echo No picture found. >&2
exit $SEDFAILURE
fi

picname=$mfdate-$(sed -n /<title>/ s/.*: \+\(.*\)<\/title>/\1/p 00 | sed -e s/[,"]//g -e s/ \+$// -e s/ /_/g -e s/’/'/g | tr [:upper:] [:lower:])

wget -q -c http://lava.nationalgeographic.com/pod/pictures/$findname -O $picname.jpg

if [ $? -ne 0 ]
then
echo Error in downloading picture. >&2
exit $WEBFAILURE
else
mfdate=$(echo $mfdate | sed s/\.//g)
mkdir -p $picdir/$(date -d $mfdate +%Y)
mv $picname.jpg $picdir/$(date -d $mfdate +%Y)/
imdisplay $picdir/$(date -d $mfdate +%Y)/$picname.jpg &
fi

echo Done.
rm -f 00

exit 0

Tagged:

§ Leave a Reply