0

Can't retrieve "event" from JSON

Hey, I'm a fairly new developer so forgive me if the answer to my problem is simple, but I don't see any way around it. So I'm building a little mashup for a class that combines a forecast and a list of sporting events when a location is entered. I'm pulling the weather from the weather underground API on YQL and the events from the Upcoming API through YQL as well. I have no problem pulling the forecast info from the JSON returned by weather underground, but I can't pull anything from the Upcoming JSON because it seems to me like since the events are labeled "event", I can't call it via javascript because it's a restricted keyword obviously. Sorry if I'm confusing you, here's some code if it helps. Thanks

CODE
<script type="text/javascript" charset="utf-8">
getwe = function(){
var forediv = document.getElementById('weather');
var sportsdiv = document.getElementById('sports');
function seed(w){
if(w.query.results.results[0]){
var resw = w.query.results.results[0].forecast.simpleforecast.forecastday;
var out = '<h2>'+resw[0].high.fahrenheit+'</h2><h2>'+resw[0].low.fahrenheit+'</h2><h2>'+resw[0].conditions+'</h2>';
forediv.innerHTML = out;
} else {
forediv.innerHTML = '<h3>No results found.</h3>';
}

if(w.query.results.results[1]){
var rese = w.query.results.results[1].event;
var out = '<h2>'+rese[0].name+'</h2><h2>'+rese[0].start_date+'</h2><h2>'+rese[0].venue_name+'</h2>';
sports.innerHTML = out;
}else{
sports.innerHTML = '<h3>No results found.</h3>';
};

}
function doSearch(){

forediv.innerHTML = '<h2>Weather loading..</h2>';
sportsdiv.innerHTML = '<h2>Events loading..</h2>';
var query = document.getElementById('search').value;
var qurl1 = '%27'+query+'%27';
var qurl2 = '%27'+query+'%27%22';
var url1 = 'select * from yql.query.multi where queries="select '+
'* from wunderground.forecast where location=';
var url2 = ';select * from upcoming.events where '+
'category_id=8 and location=';
var api ='http://query.yahooapis.com/v1/public/yql?q='+
encodeURIComponent(url1)+
''+qurl1+''+
encodeURIComponent(url2)+
''+qurl2+''+
'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'+
'&callback=getwe.w';
var s = document.createElement('script');
s.setAttribute('src',api);
document.getElementsByTagName('head')[0].appendChild(s);
}
document.getElementById('mainform').onsubmit = function(){
doSearch();
return false;
}
return {
w:seed
}
}();
</script>

by
1 Reply


  • QUOTE(aziz! @ 24 Feb 2011 12:20 PM)
    Hey, I'm a fairly new developer so forgive me if the answer to my problem is simple, but I don't see any way around it. So I'm building a little mashup for a class that combines a forecast and a list of sporting events when a location is entered. I'm pulling the weather from the weather underground API on YQL and the events from the Upcoming API through YQL as well. I have no problem pulling the forecast info from the JSON returned by weather underground, but I can't pull anything from the Upcoming JSON because it seems to me like since the events are labeled "event", I can't call it via javascript because it's a restricted keyword obviously. Sorry if I'm confusing you, here's some code if it helps. Thanks

    CODE
    <!--ec1--><!--c2--></code>
    0
This forum is locked.

Recent Posts

in Upcoming API - General Questions