Tuesday, November 8, 2016

Getting Sunrise and Sunset Time of any Country using YQL(Yahoo API)


///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
t=document.createElement("Table");
t.setAttribute("border","3");
$(document).ready(function(){
 $.ajax( {
     url: 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.states%20where%20place%3D23424848&format=json&diagnostics=true',
   type: 'POST',
async:false,
        success: function(response) {
pp=document.createElement("tr");
q1=document.createElement("th");
q1.innerHTML="STATENAME";
q2=document.createElement("th");
q2.innerHTML="SUNRISE";
q3=document.createElement("th");
q3.innerHTML="SUNSET";
pp.appendChild(q1);
pp.appendChild(q2);
pp.appendChild(q3);
t.appendChild(pp);
console.log(response);
v=response.query.results.place;
l=v.length;
for(i=0;i<l;i++)
{
statename=v[i].name;
placeid=v[i].woeid;
z=document.createElement("tr");
y=document.createElement("td");
y.innerHTML=statename;
z.appendChild(y);

console.log(statename);
rrr="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D"+placeid+"&format=json&diagnostics=true";
$.ajax( {
url: rrr,
async:false,
success: function(datareturned) {

console.log(datareturned);
sunrisetime=datareturned.query.results.channel.astronomy.sunrise;
y1=document.createElement("td");
y1.innerHTML=sunrisetime;
sunsettime=datareturned.query.results.channel.astronomy.sunset;
y2=document.createElement("td");
y2.innerHTML=sunsettime;
z.appendChild(y1);
z.appendChild(y2);
t.appendChild(z);
}
});
}

document.getElementsByTagName("body")[0].appendChild(t);}
    });
});

</script>
</head>
<body>
</body>
</html>



</html>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

No comments:

Post a Comment