随便从qq的天气里抓取了相应的天气预报,温度的问题解决了,但是天气图标的问题还是需要另外想办法。
写了一个简单的处理函数
简单说明:
1、针对通常天气里带多云转阴天,或者大雨转晴这样的情况进行处理,主要是针对转来处理,取转后面的信息
2、将天气的图标和相应的关键词对应,比如“多云”对应一个“云”字,阵雨、雷雨、大雨对应一个“雨”,放入数组,有优先级,排在前面的优先级高
3、使用循环将数组中的关键词和当前的天气来匹配,一旦匹配到就跳出循环
4、针对匹配到的天气,再匹配相应的图片
5、函数直接根据输入的天气,输出对应的天气图片
Code
function getWeather(weather)
dim newStr
if instr(weather,"转")>0 then
arrStr=split(weather,"转")
newStr=arrStr(1)
else
newStr=weather
end if
dim word,selstr
word=Array("晴","阴","云","雨","雪")
for i=0 to ubound(word)
if instr(newStr,word(i))>0 then
selstr=word(i)
exit for
end if
next
select case selstr
case "晴":getWeather="fine.gif"
case "阴":getWeather="cloudy.gif"
case "云":getWeather="Cloud.gif"
case "雨":getWeather="Rain.gif"
case "雪":getWeather="Snow.gif"
case else:getWeather="fine.gif"
end select
end function
function getWeather(weather)
dim newStr
if instr(weather,"转")>0 then
arrStr=split(weather,"转")
newStr=arrStr(1)
else
newStr=weather
end if
dim word,selstr
word=Array("晴","阴","云","雨","雪")
for i=0 to ubound(word)
if instr(newStr,word(i))>0 then
selstr=word(i)
exit for
end if
next
select case selstr
case "晴":getWeather="fine.gif"
case "阴":getWeather="cloudy.gif"
case "云":getWeather="Cloud.gif"
case "雨":getWeather="Rain.gif"
case "雪":getWeather="Snow.gif"
case else:getWeather="fine.gif"
end select
end function