sh/bash/dash/ksh/zsh等Shell脚本
-
percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
-
联系:
#1
帖子
由 percy » 2008-04-07 20:12
直接解压运行
运行效果
代码: 全选
./weather1day.sh
please keyin the city in chinese
city:新余
**********************************************************
新余:
今天天气:
温度:20℃~30℃ 上午:多云 下午:多云 今晚:多云
明天天气:
温度:22℃~30℃ 上午:多云 下午:多云 明晚:多云,雷雨
**********************************************************
用下列命令可以得到city code
代码: 全选
wget -O weather265com http://weather.265.com/
iconv -c -f gb2312 -t utf8 weather265com >weather265comutf8
grep "new Array" weather265comutf8 |sed 's/new Array//g'|grep -v var|tail -n 355|sed 's/(\"//g'|sed 's/\")//g'|sed 's/,//g'|sed 's/"//'|sed 's/"/ /g'|cut -b3-
代码: 全选
./weather3day.sh
/tmp/weathertmp
请输入要查询天气的城市名:樟树
--20:11:13-- http://php.weather.sina.com.cn/search.php?city=%D5%C1%CA%F7&dpc=1
=> `/tmp/weathertmp/sinaweather'
正在解析主机 php.weather.sina.com.cn... 202.108.33.50
Connecting to php.weather.sina.com.cn|202.108.33.50|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/html]
[ <=> ] 17,040 --.--K/s
20:11:13 (207.92 KB/s) - `/tmp/weathertmp/sinaweather' saved [17040]
########################今日 樟树#######################
08年04月07日-08日星期一
天气:多云转中雨 27℃~18℃
风力:≤3级 至 3-4级
* 污染指数:3,中。气象条件对空气污染物稀释、扩散和清除无明显影响,易感人群应适当减少室外活动时间。
* 紫外线指数:2,弱。紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。
* 舒适度指数:1,较舒适。白天天气晴好,您在这种天气条件下,会感觉早晚凉爽、舒适,午后偏热。
* 体感指数:最低温度15°C,最高温度28°C
* 防晒指数:2,较弱。紫外线强度较弱,建议涂擦SPF在12-15之间,PA+的防晒护肤品。
* 中暑指数:0,无。温度不高,其他各项气象条件适宜,中暑机率极低。
* 穿衣指数:3,暖。建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。
* 空调指数:4,较少开启。您将感到很舒适,一般不需要开启空调。
* 洗车指数:4,不宜。不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。
* 钓鱼指数:1,适宜。白天风和日丽,适宜垂钓,渺渺蓝天,悠悠白云将陪伴你度过愉快的垂钓时光。
########################明日 樟树#######################
08年04月08日-09日星期二
天气:中雨转大雨 18℃~23℃
风力:≤3级
* 污染指数:1,优。气象条件非常有利于空气污染物稀释、扩散和清除,可在室外正常活动。
* 紫外线指数:1,最弱。属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。
* 舒适度指数:0,舒适。白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。
* 体感指数:最低温度16°C,最高温度21°C
* 防晒指数:1,弱。属弱紫外辐射天气,长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。
* 中暑指数:0,无。温度不高,其他各项气象条件适宜,中暑机率极低。
* 穿衣指数:4,舒适。建议着薄型套装或牛仔衫裤等春秋过渡装。年老体弱者宜着套装、夹克衫等。
* 空调指数:4,较少开启。您将感到很舒适,一般不需要开启空调。
* 洗车指数:4,不宜。不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。
* 钓鱼指数:3,不宜。天气不好,不适合垂钓。
########################后天 樟树#######################
08年04月09日-10日星期三
天气:阵雨 16℃~22℃
风力:≤3级
* 污染指数:2,良。气象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。
* 紫外线指数:1,最弱。属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。
* 舒适度指数:0,舒适。白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。
* 体感指数:最低温度14°C,最高温度20°C
* 防晒指数:1,弱。属弱紫外辐射天气,长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。
* 中暑指数:0,无。温度不高,其他各项气象条件适宜,中暑机率极低。
* 穿衣指数:4,舒适。建议着薄型套装或牛仔衫裤等春秋过渡装。年老体弱者宜着套装、夹克衫等。
* 空调指数:4,较少开启。您将感到很舒适,一般不需要开启空调。
* 洗车指数:4,不宜。不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。
* 钓鱼指数:3,不宜。天气不好,不适合垂钓。
[/code]
-
附件
-
- weather3day.tar.gz
- 来自新浪网天气频道
可以查看3天天气 - (993 Bytes) 已下载 96 次
-
- weather1day.tar.gz
- 可以查看一天天气
- (3.82 KiB) 已下载 338 次
上次由
percy 在 2008-04-07 20:56,总共编辑 2 次。
-
percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
-
联系:
#2
帖子
由 percy » 2008-04-07 20:18
代码: 全选
cat weather1day.sh
#!/bin/bash
#Copyright (c) 2007 bones7456 (bones7456@gmail.com)
#License: GPLv3
echo "please keyin the city in chinese"
echo -n "city:"
read city
city=`grep "$city" ./city.txt |cut -d "-" -f1`
#城市代码,留空可自动检测(自动检测不一定精确),城市代码可在 http://weather.265.com 上查询,是个5位的数字
#city=
if [ -n "$city" ] ;then
wid=${city}
else
wget -q -O /tmp/weather.html 'http://weather.265.com/get_weather.php?action=get_city';
wid=`iconv -f gbk -t utf8 /tmp/weather.html | grep 'wid_265=' | sed -e 's/document\.cookie\ =\ "wid_265=//' | sed -e 's/".*//g'`;
fi
#echo "wid=${wid}"
wget -q -O /tmp/weather.html "http://weather.265.com/weather/${wid}.htm";
str=`iconv -f gbk -t utf8 /tmp/weather.html | grep 'show_weather' | sed -e 's/show_weather("//g'|sed -e 's/),\ "hd\.htm.*//g' | sed -e 's/new Array(//g' | sed -e "s/[\"|\ ]//g" | sed -e "s/,'/ /g" |sed -e "s/'//g"|sed -e "s/index.htm#$wid//g"|sed -e "s/),);//g"|sed -e "s/),//g"|sed -e "s/hz.htm#$wid//g"|sed -e "s/);//g"|sed -e "s/[[xd]b|[xn]|[hd]|[hb]|囗囗囗囗|[ga]].htm#$wid//g"`;
#echo "str=${str}";
AnArray=( ${str} );
time=`date +%k`;
#echo "time=$time"
echo "**********************************************************"
#if [ ${time} -gt 18 ] ; then
echo ${AnArray[0]}:
echo "今天天气:"
echo 温度:${AnArray[1]} 上午:${AnArray[2]} 下午:${AnArray[3]} 今晚:${AnArray[4]}
#echo 明天:${AnArray[6]}
echo "明天天气:"
echo 温度:${AnArray[5]} 上午:${AnArray[6]} 下午:${AnArray[7]} 明晚:${AnArray[8]}
#elif [ ${time} -gt 12 ] ; then
#echo ${AnArray[0]}: ${AnArray[1]} 下午:${AnArray[3]};晚上:${AnArray[4]}
#else
#echo ${AnArray[0]}: ${AnArray[1]} 上午:${AnArray[2]};下午:${AnArray[3]}
#fi
echo "**********************************************************"
rm -f /tmp/weather.html;
exit 0;
代码: 全选
cat weather3day.sh
#!/bin/bash
#Copyright (c) 2007 percy (pengjianqing@sina.com.cn)
#License: GPLv3
#2008年 04月 07日 星期一 17:43:25 CST
#
mkdir -p "/tmp/weathertmp"
tmp="/tmp/weathertmp"
echo $tmp
read -p "请输入要查询天气的城市名:" city
a=`echo "$city" | iconv -c -f utf-8 -t gb2312 | LANG=C sed 's/./&\n/g' | sed -n '$!l' |
while read str;do
str=${str%$}
if [ ${#str} -eq 3 ];then
printf "%%%X" "0${str}"
elif [ "X${str}" == "X" ];then
echo -n '%20'
else
echo -n $str
fi
done
echo`
wget -O "${tmp}/sinaweather" "http://php.weather.sina.com.cn/search.php?city=${a}&dpc=1"
iconv -c -f gb2312 -t utf8 "${tmp}/sinaweather" >"${tmp}/sina-utf8"
grep $city "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1 |sed 's/^/########################/g'|sed 's/$/#######################/g' |head -n 3 >"${tmp}/DAY" #今日,明日,后天
year=`date |cut -b3-7`
grep "$year" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|sed 's/ //g'|sed 's/^/YEAR/g' >"${tmp}/TIME"
grep 污染指数 "${tmp}/sina-utf8" -n|awk -F "<span>" '{print $2,$3,$4,$5,$6,$7,$8,$9,$10,$11}'|sed 's/<\/span>//g'|sed 's/<\/p>//g' |sed 's/<\/div>//g'>"${tmp}/INDEX" #得到指数信息
grep "Weather_TP" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|sed 's/^/TP/g' >"${tmp}/TP" #得到天气信息
grep "Weather_W" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|cut -d ";" -f2 |sed 's/^/@/g' >"${tmp}/W" #得到风力信息
cat "${tmp}/DAY" >"${tmp}/ALL"
cat "${tmp}/TIME" >>"${tmp}/ALL"
cat "${tmp}/TP" >>"${tmp}/ALL"
cat "${tmp}/W" >>"${tmp}/ALL"
cat "${tmp}/INDEX" >>"${tmp}/ALL"
awk '{a[NR]=$0}END{for(i=1;i<=NR/5;i++)printf "%s\t%s\t%s\t%s\t%s\n",a[i],a[i+NR/5],a[i+2*NR/5],a[i+3*NR/5],a[i+4*NR/5]}' "${tmp}/ALL" >"${tmp}/SUM1"
cat "${tmp}/SUM1"|sed 's/<p>/\n*/g'|sed 's/污染指数/\n* 污染指数/g'|sed 's/TP/\n天气:/g'|sed 's/@/\n/g'|sed 's/YEAR/\n/g' >"${tmp}/SUM2"
cat "${tmp}/SUM2"
rm -r "${tmp}"
受ee启发,改成这样,就太简单了
代码: 全选
cat weatherw3m.sh
#########################################################################
# Author: PengJianqing@sina.com
# Created Time: 2008年04月08日 星期二 12时49分45秒
# File Name: weatherw3m.sh
# Description:
#########################################################################
#!/bin/bash
read -p "input city in pinyin:" city
w3m -dump -no-cookie "http://php.weather.sina.com.cn/search.php?city=${city}&dpc=1"|grep ""
上次由
percy 在 2008-04-08 12:57,总共编辑 1 次。
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#3
帖子
由 eexpress » 2008-04-07 22:14
复杂。
我的简单
☎ cat weather-长沙天气预报
#!/bin/bash
notify-send -u critical -t 5000 -i '/home/exp/媒体/●图标/128软件png/●iPhone/weather.png' '长沙天气预报' "`w3m -dump -no-cookie
http://www.15882.com/tianqi/changsha.htm|grep ^20`"
找什么城市哦。罗嗦了不。解析,一个grep就完成了。
● 鸣学
-
aBiNg
- 帖子: 1331
- 注册时间: 2006-07-09 12:22
- 来自: 南京
#4
帖子
由 aBiNg » 2008-04-07 23:00
纯技术顶帖。
-
fanxia
- 帖子: 1
- 注册时间: 2008-04-03 0:13
#6
帖子
由 fanxia » 2008-04-07 23:45
值得学习,呵呵~
虽然比较复杂。
-
percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
-
联系:
#7
帖子
由 percy » 2008-04-08 12:27
eexpress 写了:复杂。
我的简单
☎ cat weather-长沙天气预报
#!/bin/bash
notify-send -u critical -t 5000 -i '/home/exp/媒体/●图标/128软件png/●iPhone/weather.png' '长沙天气预报' "`w3m -dump -no-cookie
http://www.15882.com/tianqi/changsha.htm|grep ^20`"
找什么城市哦。罗嗦了不。解析,一个grep就完成了。
ee的果然牛,学习了
-
percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
-
联系:
#8
帖子
由 percy » 2008-04-08 13:11
percy 写了:代码: 全选
cat weather1day.sh
#!/bin/bash
#Copyright (c) 2007 bones7456 (bones7456@gmail.com)
#License: GPLv3
echo "please keyin the city in chinese"
echo -n "city:"
read city
city=`grep "$city" ./city.txt |cut -d "-" -f1`
#城市代码,留空可自动检测(自动检测不一定精确),城市代码可在 http://weather.265.com 上查询,是个5位的数字
#city=
if [ -n "$city" ] ;then
wid=${city}
else
wget -q -O /tmp/weather.html 'http://weather.265.com/get_weather.php?action=get_city';
wid=`iconv -f gbk -t utf8 /tmp/weather.html | grep 'wid_265=' | sed -e 's/document\.cookie\ =\ "wid_265=//' | sed -e 's/".*//g'`;
fi
#echo "wid=${wid}"
wget -q -O /tmp/weather.html "http://weather.265.com/weather/${wid}.htm";
str=`iconv -f gbk -t utf8 /tmp/weather.html | grep 'show_weather' | sed -e 's/show_weather("//g'|sed -e 's/),\ "hd\.htm.*//g' | sed -e 's/new Array(//g' | sed -e "s/["|\ ]//g" | sed -e "s/,'/ /g" |sed -e "s/'//g"|sed -e "s/index.htm#$wid//g"|sed -e "s/),);//g"|sed -e "s/),//g"|sed -e "s/hz.htm#$wid//g"|sed -e "s/);//g"|sed -e "s/[[xd]b|[xn]|[hd]|[hb]|囗囗囗囗|[ga]].htm#$wid//g"`;
#echo "str=${str}";
AnArray=( ${str} );
time=`date +%k`;
#echo "time=$time"
echo "**********************************************************"
#if [ ${time} -gt 18 ] ; then
echo ${AnArray[0]}:
echo "今天天气:"
echo 温度:${AnArray[1]} 上午:${AnArray[2]} 下午:${AnArray[3]} 今晚:${AnArray[4]}
#echo 明天:${AnArray[6]}
echo "明天天气:"
echo 温度:${AnArray[5]} 上午:${AnArray[6]} 下午:${AnArray[7]} 明晚:${AnArray[8]}
#elif [ ${time} -gt 12 ] ; then
#echo ${AnArray[0]}: ${AnArray[1]} 下午:${AnArray[3]};晚上:${AnArray[4]}
#else
#echo ${AnArray[0]}: ${AnArray[1]} 上午:${AnArray[2]};下午:${AnArray[3]}
#fi
echo "**********************************************************"
rm -f /tmp/weather.html;
exit 0;
代码: 全选
cat weather3day.sh
#!/bin/bash
#Copyright (c) 2007 percy (pengjianqing@sina.com.cn)
#License: GPLv3
#2008年 04月 07日 星期一 17:43:25 CST
#
mkdir -p "/tmp/weathertmp"
tmp="/tmp/weathertmp"
echo $tmp
read -p "请输入要查询天气的城市名:" city
a=`echo "$city" | iconv -c -f utf-8 -t gb2312 | LANG=C sed 's/./&\n/g' | sed -n '$!l' |
while read str;do
str=${str%$}
if [ ${#str} -eq 3 ];then
printf "%%%X" "0${str}"
elif [ "X${str}" == "X" ];then
echo -n '%20'
else
echo -n $str
fi
done
echo`
wget -O "${tmp}/sinaweather" "http://php.weather.sina.com.cn/search.php?city=${a}&dpc=1"
iconv -c -f gb2312 -t utf8 "${tmp}/sinaweather" >"${tmp}/sina-utf8"
grep $city "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1 |sed 's/^/########################/g'|sed 's/$/#######################/g' |head -n 3 >"${tmp}/DAY" #今日,明日,后天
year=`date |cut -b3-7`
grep "$year" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|sed 's/ //g'|sed 's/^/YEAR/g' >"${tmp}/TIME"
grep 污染指数 "${tmp}/sina-utf8" -n|awk -F "<span>" '{print $2,$3,$4,$5,$6,$7,$8,$9,$10,$11}'|sed 's/<\/span>//g'|sed 's/<\/p>//g' |sed 's/<\/div>//g'>"${tmp}/INDEX" #得到指数信息
grep "Weather_TP" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|sed 's/^/TP/g' >"${tmp}/TP" #得到天气信息
grep "Weather_W" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|cut -d ";" -f2 |sed 's/^/@/g' >"${tmp}/W" #得到风力信息
cat "${tmp}/DAY" >"${tmp}/ALL"
cat "${tmp}/TIME" >>"${tmp}/ALL"
cat "${tmp}/TP" >>"${tmp}/ALL"
cat "${tmp}/W" >>"${tmp}/ALL"
cat "${tmp}/INDEX" >>"${tmp}/ALL"
awk '{a[NR]=$0}END{for(i=1;i<=NR/5;i++)printf "%s\t%s\t%s\t%s\t%s\n",a[i],a[i+NR/5],a[i+2*NR/5],a[i+3*NR/5],a[i+4*NR/5]}' "${tmp}/ALL" >"${tmp}/SUM1"
cat "${tmp}/SUM1"|sed 's/<p>/\n*/g'|sed 's/污染指数/\n* 污染指数/g'|sed 's/TP/\n天气:/g'|sed 's/@/\n/g'|sed 's/YEAR/\n/g' >"${tmp}/SUM2"
cat "${tmp}/SUM2"
rm -r "${tmp}"
受ee启发,改成这样,就太简单了
代码: 全选
cat weatherw3m.sh
#########################################################################
# Author: PengJianqing@sina.com
# Created Time: 2008年04月08日 星期二 12时49分45秒
# File Name: weatherw3m.sh
# Description:
#########################################################################
#!/bin/bash
read -p "input city in pinyin:" city
w3m -dump -no-cookie "http://php.weather.sina.com.cn/search.php?city=${city}&dpc=1"|grep ""
代码: 全选
cat weatherw3m2.sh
#########################################################################
# Author: PengJianqing@sina.com
# Created Time: 2008年04月08日 星期二 12时57分45秒
# File Name: weatherw3m2.sh
# Description:
#########################################################################
#!/bin/bash
#read -p "input city in pinyin:" city
notify-send -u critical -t 5000 "`w3m -dump -no-cookie "http://www.15882.com/tianqi/$1.htm"|grep ^20`"
-
percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
-
联系:
#9
帖子
由 percy » 2008-04-08 13:14
percy 写了:代码: 全选
cat weather1day.sh
#!/bin/bash
#Copyright (c) 2007 bones7456 (bones7456@gmail.com)
#License: GPLv3
echo "please keyin the city in chinese"
echo -n "city:"
read city
city=`grep "$city" ./city.txt |cut -d "-" -f1`
#城市代码,留空可自动检测(自动检测不一定精确),城市代码可在 http://weather.265.com 上查询,是个5位的数字
#city=
if [ -n "$city" ] ;then
wid=${city}
else
wget -q -O /tmp/weather.html 'http://weather.265.com/get_weather.php?action=get_city';
wid=`iconv -f gbk -t utf8 /tmp/weather.html | grep 'wid_265=' | sed -e 's/document\.cookie\ =\ "wid_265=//' | sed -e 's/".*//g'`;
fi
#echo "wid=${wid}"
wget -q -O /tmp/weather.html "http://weather.265.com/weather/${wid}.htm";
str=`iconv -f gbk -t utf8 /tmp/weather.html | grep 'show_weather' | sed -e 's/show_weather("//g'|sed -e 's/),\ "hd\.htm.*//g' | sed -e 's/new Array(//g' | sed -e "s/["|\ ]//g" | sed -e "s/,'/ /g" |sed -e "s/'//g"|sed -e "s/index.htm#$wid//g"|sed -e "s/),);//g"|sed -e "s/),//g"|sed -e "s/hz.htm#$wid//g"|sed -e "s/);//g"|sed -e "s/[[xd]b|[xn]|[hd]|[hb]|囗囗囗囗|[ga]].htm#$wid//g"`;
#echo "str=${str}";
AnArray=( ${str} );
time=`date +%k`;
#echo "time=$time"
echo "**********************************************************"
#if [ ${time} -gt 18 ] ; then
echo ${AnArray[0]}:
echo "今天天气:"
echo 温度:${AnArray[1]} 上午:${AnArray[2]} 下午:${AnArray[3]} 今晚:${AnArray[4]}
#echo 明天:${AnArray[6]}
echo "明天天气:"
echo 温度:${AnArray[5]} 上午:${AnArray[6]} 下午:${AnArray[7]} 明晚:${AnArray[8]}
#elif [ ${time} -gt 12 ] ; then
#echo ${AnArray[0]}: ${AnArray[1]} 下午:${AnArray[3]};晚上:${AnArray[4]}
#else
#echo ${AnArray[0]}: ${AnArray[1]} 上午:${AnArray[2]};下午:${AnArray[3]}
#fi
echo "**********************************************************"
rm -f /tmp/weather.html;
exit 0;
代码: 全选
cat weather3day.sh
#!/bin/bash
#Copyright (c) 2007 percy (pengjianqing@sina.com.cn)
#License: GPLv3
#2008年 04月 07日 星期一 17:43:25 CST
#
mkdir -p "/tmp/weathertmp"
tmp="/tmp/weathertmp"
echo $tmp
read -p "请输入要查询天气的城市名:" city
a=`echo "$city" | iconv -c -f utf-8 -t gb2312 | LANG=C sed 's/./&\n/g' | sed -n '$!l' |
while read str;do
str=${str%$}
if [ ${#str} -eq 3 ];then
printf "%%%X" "0${str}"
elif [ "X${str}" == "X" ];then
echo -n '%20'
else
echo -n $str
fi
done
echo`
wget -O "${tmp}/sinaweather" "http://php.weather.sina.com.cn/search.php?city=${a}&dpc=1"
iconv -c -f gb2312 -t utf8 "${tmp}/sinaweather" >"${tmp}/sina-utf8"
grep $city "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1 |sed 's/^/########################/g'|sed 's/$/#######################/g' |head -n 3 >"${tmp}/DAY" #今日,明日,后天
year=`date |cut -b3-7`
grep "$year" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|sed 's/ //g'|sed 's/^/YEAR/g' >"${tmp}/TIME"
grep 污染指数 "${tmp}/sina-utf8" -n|awk -F "<span>" '{print $2,$3,$4,$5,$6,$7,$8,$9,$10,$11}'|sed 's/<\/span>//g'|sed 's/<\/p>//g' |sed 's/<\/div>//g'>"${tmp}/INDEX" #得到指数信息
grep "Weather_TP" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|sed 's/^/TP/g' >"${tmp}/TP" #得到天气信息
grep "Weather_W" "${tmp}/sina-utf8" |cut -d ">" -f2|cut -d "<" -f1|cut -d ";" -f2 |sed 's/^/@/g' >"${tmp}/W" #得到风力信息
cat "${tmp}/DAY" >"${tmp}/ALL"
cat "${tmp}/TIME" >>"${tmp}/ALL"
cat "${tmp}/TP" >>"${tmp}/ALL"
cat "${tmp}/W" >>"${tmp}/ALL"
cat "${tmp}/INDEX" >>"${tmp}/ALL"
awk '{a[NR]=$0}END{for(i=1;i<=NR/5;i++)printf "%s\t%s\t%s\t%s\t%s\n",a[i],a[i+NR/5],a[i+2*NR/5],a[i+3*NR/5],a[i+4*NR/5]}' "${tmp}/ALL" >"${tmp}/SUM1"
cat "${tmp}/SUM1"|sed 's/<p>/\n*/g'|sed 's/污染指数/\n* 污染指数/g'|sed 's/TP/\n天气:/g'|sed 's/@/\n/g'|sed 's/YEAR/\n/g' >"${tmp}/SUM2"
cat "${tmp}/SUM2"
rm -r "${tmp}"
受ee启发,改成这样,就太简单了
代码: 全选
cat weatherw3m.sh
#########################################################################
# Author: PengJianqing@sina.com
# Created Time: 2008年04月08日 星期二 12时49分45秒
# File Name: weatherw3m.sh
# Description:
#########################################################################
#!/bin/bash
read -p "input city in pinyin:" city
w3m -dump -no-cookie "http://php.weather.sina.com.cn/search.php?city=${city}&dpc=1"|grep ""
代码: 全选
cat weatherw3m2.sh
#########################################################################
# Author: PengJianqing@sina.com
# Created Time: 2008年04月08日 星期二 12时57分45秒
# File Name: weatherw3m2.sh
# Description:
#########################################################################
#!/bin/bash
#read -p "input city in pinyin:" city
notify-send -u critical -t 5000 "`w3m -dump -no-cookie "http://www.15882.com/tianqi/$1.htm"|grep ^20`"
-
percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
-
联系:
#10
帖子
由 percy » 2009-08-06 12:22
要使用notify-send需要安装libnotify-bin
sudo apt-get install libnotify-bin
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#11
帖子
由 eexpress » 2009-08-06 12:33
中文和拼音都支持的啊。
代码: 全选
☎ cat w-w天气查询.pl
#!/usr/bin/perl
if($ARGV[0]){
$a=`echo $ARGV[0]|uni2ascii -a J`;
}
else{
$a="长沙";
}
#print "$a\n";
my $r=`w3m -no-cookie -dump http://ipiciq.com/Weather/Default.aspx?q=$a`;
$r=~s/^.*查询]//s;
$r=~s/•.*//s;
$r=~s/(%|°C)/\1 ► /sg;
$r=~s/\n/ /g;
$r=~s/\ +/\ /g;
if($r=~/网络故障/){$r="拼音或中文城市名不正确。原提示:".$r;}
print $r;
● 鸣学
-
c\nc
- 帖子: 231
- 注册时间: 2007-12-25 12:51
#12
帖子
由 c\nc » 2009-08-06 15:20
提供一个方便处理的:
http://wap.weather.com.cn/wap/
输出类似于这样:
广州中心气象台发布暴雨橙色预警
海南省气象台发布暴雨橙色预警
2009年8月6日 星期四
[农历六月十六]
北京
天气:阵雨
气温:29度到23度
风向风力:微风小于3级
紫外线指数:弱
穿衣指数:热
查看详细北京天气预报
48小时: 阴转多云 31℃~24℃ 微风小于3级
72小时: 多云转阴 32℃~25℃ 微风小于3级
国内天气| 国际天气| 旅游景区
气象灾害预警
天气趋势预报| 图说天气
气象新闻| 热点追踪| 气象百科
=气象社区=
互动主题1
互动主题2
首页
# 隐私保护 版权所有
# 中国气象局公共气象服务中心 Copyright © 2000-2008
# 未经授权 严禁非法复制或镜像