AJAX 일기예보 에 맞 춘 웹 서비스의 asp
8811 단어 AJAX 일기예보 에 맞 춘 웹 서비스의 asp
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%
Session.CodePage = "65001"
Response.contentType="text/html"
Response.Expires = 0
var N=Request("n")
var Num=Request("id")
var url="http://xml.weather.yahoo.com/forecastrss?p="+N+"&u=c&id="+Num;
var xmldoc=Server.CreateObject("Microsoft.Xmlhttp");
xmldoc.open('GET',url,false);
xmldoc.send(null);
var response = xmldoc.responseXML.documentElement;
var lastNode=response.selectNodes("//rss/channel/lastBuildDate");
var cityNode=response.selectNodes("//rss/channel/yweather:location");
var windNode=response.selectNodes("//rss/channel/yweather:wind");
var atmosphereNode=response.selectNodes("//rss/channel/yweather:atmosphere");
var astronomyNode=response.selectNodes("//rss/channel/yweather:astronomy");
var conditionNode=response.selectNodes("//rss/channel/item/yweather:condition");
var forecastNode=response.selectNodes("//rss/channel/item/yweather:forecast");
var lastV=lastNode(0).firstChild.nodeValue
//
function attri(a,b,c){
return a(b).attributes.getNamedItem(c).value
}
var cityV=attri(cityNode,0,"city")
var chillV=attri(windNode,0,"chill")
var directionV=attri(windNode,0,"direction")
var speedV=attri(windNode,0,"speed")
var humidityV=attri(atmosphereNode,0,"humidity")
var visibilityV=attri(atmosphereNode,0,"visibility")
var sunriseV=attri(astronomyNode,0,"sunrise")
var sunsetV=attri(astronomyNode,0,"sunset")
var textV=attri(conditionNode,0,"text")
var codeV=attri(conditionNode,0,"code")
var tempV=attri(conditionNode,0,"temp")
//
var cityCH=EN2CH(cityV)
function EN2CH(obj){
if(obj=="Wuhan"){return " "}
else if(obj=="Nanchang"){return " "}
else if(obj=="Haikou"){return " "}
else if(obj=="Beijing"){return " "}
else if(obj=="Shanghai"){return " "}
else if(obj=="Guangzhou"){return " "}
else if(obj=="Yinchuan"){return " "}
else if(obj=="Zhengzhou"){return " "}
else if(obj=="Changsha"){return " "}
else if(obj=="Hanzhong"){return " "}
else if(obj=="Hong Kong"){return " "}
else if(obj=="Xin'an"){return " "}
else if(obj=="Chengdu"){return " "}
else if(obj=="Qingdao"){return " "}
else if(obj=="Guiyang"){return " "}
else if(obj=="Jinan"){return " "}
else if(obj=="Hefei"){return " "}
else if(obj=="Fuzhou"){return " "}
else if(obj=="Nanjing"){return " "}
else{return obj}
}
//
var windCH=wind(directionV)
function wind(a){
if(a>337 && a<=360){return " "};
else if(a>=0 && a<=22){return " "};
else if(a>22 && a<=67){return " "};
else if(a>67 && a<=112){return " "};
else if(a>112 && a<=157){return " "};
else if(a>157 && a<=202){return " "};
else if(a>202 && a<=247){return " "};
else if(a>247 && a<=292){return " "};
else if(a>292 && a<=337){return " "};
}
//
visibility=vis(visibilityV)
function vis(a){
return a/100
}
//
var textCH=tEN2CH(textV)
function tEN2CH(obj){
if(obj=="Clear"){return " "}
else if(obj=="Sunny"){return " "}
else if(obj=="Partly Cloudy"){return " "}
else if(obj=="Mostly Clear"){return " "}
else if(obj=="Mostly Sunny"){return " "}
else if(obj=="Mostly Cloudy"){return " "}
else if(obj=="Cloudy"){return " "}
else if(obj=="Sunny/Wind"){return " "}
else if(obj=="AM Clouds/PM Sun/Wind"){return " "}
else if(obj=="AM Showers"){return " "}
else{return obj}
}
//
var weaNum=weaimg(codeV)
function weaimg(obj){
return "<img src=\"http\://us\.i1\.yimg\.com/us\.yimg.com/i/us/we/52/"+obj+"\.gif\" />"
}
//
function dayEn(obj){
if(obj=="Sun"){return " "}
else if(obj=="Mon"){return " "}
else if(obj=="Tue"){return " "}
else if(obj=="Wed"){return " "}
else if(obj=="Thu"){return " "}
else if(obj=="Fri"){return " "}
else if(obj=="Sat"){return " "}
else{return obj}
}
%>
<table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="6" align="center"><%=cityCH%><br />
<%=weaNum%><br />
<%=textCH%></td>
<td align="right"> :</td>
<td align="center"><%=chillV%>°</td>
</tr>
<tr style="background-color:#E6F5FF">
<td align="right"> :</td>
<td align="center"><%=tempV%>°</td>
</tr>
<tr>
<td align="right"> :</td>
<td align="center"><%=windCH%></td>
</tr>
<tr style="background-color:#E6F5FF">
<td align="right"> :</td>
<td align="center"><%=speedV%>Kph</td>
</tr>
<tr>
<td align="right"> :</td>
<td align="center"><%=humidityV%>%</td>
</tr>
<tr style="background-color:#E6F5FF">
<td align="right"> :</td>
<td align="center"><%=visibility%>km</td>
</tr>
</table>
<table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center" class="time"><%=lastV%></td>
</tr>
<tr>
<td bgcolor="#FFFFCC"> :<%=sunriseV%></td>
<td bgcolor="#FFCC00"> :<%=sunsetV%></td>
</tr>
</table>
<table width="163" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<%
for(var i=0; i<2; i++){
var dayV=attri(forecastNode,i,"day")
var dateV=attri(forecastNode,i,"date")
var lowV=attri(forecastNode,i,"low")
var highV=attri(forecastNode,i,"high")
var texttV=attri(forecastNode,i,"text")
var codetV=attri(forecastNode,i,"code")
var dayCH=dayEn(dayV)
var texttCH=tEN2CH(texttV)
var weabmp=weaimg(codetV)
//var weatNum=weaimg(codetV)
%>
<td align="center"><%=dayCH%><br /><%=weabmp%><br /><%=texttCH%><br /> <%=highV%>°<br /> <%=lowV%>°</td>
<%
}
%>
</tr>
</table>