文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>再发一个天气预报的

再发一个天气预报的

时间:2010-04-12  来源:zhenze12345

#!/bin/bash -

WEATHER_FILE=/tmp/101010200.shtml

get_day()
{
    day=`date --date="0 day"|awk '{print $3$4}'`
    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}'`
    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
    fi
}

get_night_weather()
{
    w3m -dump  $WEATHER_FILE |grep 夜间|head -n 1|awk '{print $3" "$4$5}'
}

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


相关阅读 更多 +
排行榜 更多 +
百炼英雄抽卡技巧指南

百炼英雄抽卡技巧指南

休闲益智 下载
英雄没有闪滚雷旋风技能如何搭配

英雄没有闪滚雷旋风技能如何搭配

休闲益智 下载
英雄没有闪雷旋风BD构筑推荐

英雄没有闪雷旋风BD构筑推荐

休闲益智 下载