随笔 - 0  文章 - 3  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(4)

文章分类

文章档案

C++

linux application

linux develop

shell

tools

搜索

  •  

最新评论

[ No . 539   21 : 32 : 52  bash ] #  cat myweather.sh
#! /bin/bash

# 修改了处理过程和优化了速度
# 经过修改已经支持城市代码和城市名
# 支持同时查询多个城市天气的查询


city_code_file
= " /linux/xuexi/bash/code_city.db "
cd 
/ tmp

usage()
{
echo 
" Usage: `basename $0` [codes/citys]  "
echo
cat 
<<  CITY
1        香港     2        澳门             17       哈尔滨   28       乌鲁木齐         56       西宁
57       兰州     69       呼和浩特         78       银川     82       石家庄           84       太原
103      长春     115      沈阳             125      北京     127      天津             140      济南
150      拉萨     166      成都             179      昆明     186      西安             189      郑州
211      武汉     212      重庆             218      长沙     227      贵阳             232      桂林
244      南京     248      合肥             252      上海     255      杭州             264      南昌
276      福州     280      台北             287      厦门     292      广州             295      南宁
296      深圳     303      海口
CITY
echo

exit   0
}

getweather()
{
        
grep   " <td height=\ " 23 \ ""  ss . html  >  ss . txt
        city
= $( grep   " <td height=\ " 23 \ ""  ss . txt  |  sed  - ' 1p '   |  sed  ' s/[[:lower:][:digit:]\<\>="\/_\. ]//g ' )
        weat
= $( grep   " <td height=\ " 23 \ ""  ss . txt  |  sed  - ' 2p '   |  sed  ' s/.*center\">// '   |  sed  ' s/<.*// ' )
        temp
= $( grep   " <td height=\ " 23 \ ""  ss . txt  |  sed  - ' 4p '   |  sed  ' s/.*>// ' )
        wind
= $( grep   " <td height=\ " 23 \ ""  ss . txt  |  sed  - ' 6p '   |  sed  ' s/.*center\">// '   |  sed  ' s/<.*// ' )
        viol
= $( grep   " <td height=\ " 23 \ ""  ss . txt  |  sed  - ' 8p '   |  sed  ' s/.*center\">// '   |  sed  ' s/<.*// ' )
        aire
= $( grep   " <td height=\ " 23 \ ""  ss . txt  |  sed  - ' 10p '   |  sed  ' s/.*center\">// '   |  sed  ' s/<.*// ' )
}


getall()
{
        wget  
- / tmp / ss . html  http :// weather . qq . com / inc / ss${code} . htm  >   / dev / null  2 >& 1
        getweather
        showweather

        rm 
- f ss . html  ss . txt  >   / dev / null  2 >& 1
}

showweather()
{
        echo
        echo 
- " \t城  市:      $city "
        echo 
- " \t天  气:      $weat "
        echo 
- " \t温  度:      $temp "
        echo 
- " \t风  力:      $wind "
        echo 
- " \t空  气:      $aire "
        echo 
- " \t紫外线:      $viol "
        echo
}

# ###### MAIN #########

[[ $
1   ==   " -h "  ]]  ||  [[ $ 1   ==   " --help "  ]]  &&  usage

if  [[  - z $ 1  ]];then
        set 
103   303
fi

for  citycode in  " $@ " ; do
        code
= $( grep   - " $citycode "    $city_code_file   |  awk  ' {print $1} ' )
        
if  [[  - $code  ]];then
                getall
        
else
                echo 
" $citycode not invalid. "
                usage
        fi
done

exit   0



[
No . 540   21 : 33 : 05  bash ] #  cat code_city.db
1  香港
2  澳门
17  哈尔滨
28  乌鲁木齐
56  西宁
57  兰州
69  呼和浩特
78  银川
82  石家庄
84  太原
103  长春
115  沈阳
125  北京
127  天津
140  济南
150  拉萨
166  成都
179  昆明
186  西安
189  郑州
211  武汉
212  重庆
218  长沙
227  贵阳
232  桂林
244  南京
248  合肥
252  上海
255  杭州
264  南昌
276  福州
280  台北
287  厦门
292  广州
295  南宁
296  深圳
303  海口
posted on 2006-12-14 08:32 崔少伟 阅读(472) 评论(0)  编辑 收藏 引用 所属分类: script language

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理