I am LAZY bones? AN ancient AND boring SITE

一个天气预报的脚本

闲来无事,写了天气预报的脚本,与大家分享。
本人菜鸟,如有任何问题或建议,欢迎指正。谢谢。

数据来自 http://weather.265.com

#!/bin/bash
#Copyright (c) 2007 bones7456 (bones7456@gmail.com)
#License: GPLv3
#version 20080524
 
#城市代码,留空可自动检测(自动检测不一定精确),城市代码可在 http://weather.265.com 上查询,是个5位的数字
#city=58457
 
if [ -n "$city" ] ;then
	wid=${city}
else
	wget -q -O /tmp/weather.html 'http://www.265.com/lookupcity';
	wid=`awk -F "'" '{print $2}' /tmp/weather.html`;
fi
#echo ${wid};
wget -q -O /tmp/weather.html "http://www.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"`;
#echo ${str};
AnArray=( ${str} );
time=`date +%k`;
if [ ${time} -gt 18 ] ; then
	echo ${AnArray[0]}${AnArray[1]} 今晚:${AnArray[4]};明天:${AnArray[6]}
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
rm -f /tmp/weather.html;
exit 0;

最后修改时间: 2007年09月04日 14:27

本文章发表于: 2007年09月04日 14:27 | 所属分类:CLI软件, 精华. | 您可以在此订阅本文章的所有评论. | 您也可以发表评论, 或从您的网站trackback.

3 个评论 关于: “一个天气预报的脚本”

  1. bones7456 : 语音播报天气的脚本 在 2008年10月03日 19:36 说:回复

    […] 我以前写的一个天气预报脚本,由xiooli同学完成了语音部分,嘿嘿,效果还不错的哦~ 下载地址: http://ftp.ubuntu.org.cn/home/xiooli/say_weather.tar.gzhttp://linuxfire.com.cn/~lily/say_weather.tar.gz […]

  2. Shellex 在 2009年03月28日 11:14 说:回复

    没有负温度的语音

    • bones7456 在 2009年03月29日 09:51 说:回复

      呃…漏了…

bones7456 发表评论




取消