再一次修改,修正了一个在从每个月1号至9号无法正常显示的BUG
#!/bin/bash -
WEATHER_FILE=/root/.conky/101010200.shtml
get_day()
{
day=`date --date="0 day"|awk '{print $3$4}'|sed -n 's/^0//g;p'`
day=`w3m $WEATHER_FILE -dump|grep $day|grep "\℃"|awk '{print $2}'`
if [ "$day" = "夜间" ]
then
echo "今日夜间"
return 1
elif [ "$day" = "白天" ]
then
echo "今日白天"
return 2
fi
}
get_weather()
{
day=`date --date="$1 day"|awk '{print $3$4}'|sed -n 's/^0//g;p'`
weather=`w3m $WEATHER_FILE -dump|grep $day|grep '\℃'|awk '{print $4" "$5$6}'|sed -n 's/\℃/度/g;p'`
if [ "$weather" = " " ] || [ "$weather" = "" ]
then
echo "尚无信息"
else
echo $weather|sed -n 's/\(.\)温/最\1/;p'
fi
}
get_night_weather()
{
w3m -dump $WEATHER_FILE |grep 夜间|grep -v `date --date="-1 day"|awk '{print $3$4}'`|head -n 1|awk '{print $3" "$4$5}'|sed -n 's/\℃/度/g;p'|sed -n 's/\(.\)温/最\1/;p'
}
if [ ! -f $WEATHER_FILE ]
then
echo "尚无信息"
exit 1
fi
case $1 in
1 )
get_day
;;
2 )
get_weather 0
;;
3 )
get_day 1>/dev/null 2>&1
if [ "$?" -eq 1 ]
then
echo "明日白天"
else
echo "今日夜间"
fi
;;
4 )
get_day 1>/dev/null 2>&1
if [ "$?" -eq 1 ]
then
get_weather 1
else
get_night_weather
fi
;;
esac
|
阅读(1336) | 评论(0) | 转发(0) |