2011-01-01 09:09:02 +03:00
|
|
|
if (phantom.state.length === 0) {
|
2010-12-28 09:39:12 +03:00
|
|
|
var city = 'Mountain View';
|
2011-01-15 09:24:47 +03:00
|
|
|
if (phantom.args.length > 0) {
|
|
|
|
city = phantom.args.join(' ');
|
2010-12-28 09:39:12 +03:00
|
|
|
}
|
2011-01-01 09:09:02 +03:00
|
|
|
phantom.state = city;
|
2011-01-01 07:10:34 +03:00
|
|
|
console.log('Loading ' + city);
|
2010-12-28 09:39:12 +03:00
|
|
|
phantom.open(encodeURI('http://www.google.com/ig/api?weather=' + city));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (phantom.loadStatus === 'fail') {
|
2011-01-01 07:10:34 +03:00
|
|
|
console.log('Unable to access network');
|
2011-01-01 09:17:51 +03:00
|
|
|
} else {
|
|
|
|
if (document.querySelectorAll('problem_cause').length > 0) {
|
|
|
|
console.log('No data available for ' + phantom.state);
|
|
|
|
} else {
|
|
|
|
function data (s, e) {
|
|
|
|
var el;
|
|
|
|
e = e || document;
|
|
|
|
el = e.querySelector(s);
|
|
|
|
return el ? el.attributes.data.value : undefined;
|
|
|
|
};
|
2010-12-28 09:39:12 +03:00
|
|
|
|
2011-01-01 09:17:51 +03:00
|
|
|
console.log('');
|
|
|
|
console.log('City: ' + data('weather > forecast_information > city'));
|
|
|
|
console.log('Current condition: ' + data('weather > current_conditions > condition'));
|
|
|
|
console.log('Temperature: ' + data('weather > current_conditions > temp_f') + ' F');
|
|
|
|
console.log(data('weather > current_conditions > humidity'));
|
|
|
|
console.log(data('weather > current_conditions > wind_condition'));
|
|
|
|
console.log('');
|
2010-12-28 09:39:12 +03:00
|
|
|
|
2011-01-01 09:17:51 +03:00
|
|
|
var forecasts = document.querySelectorAll('weather > forecast_conditions');
|
|
|
|
for (var i = 0; i < forecasts.length; ++i) {
|
|
|
|
var f = forecasts[i];
|
|
|
|
console.log(data('day_of_week', f) + ': ' +
|
|
|
|
data('low', f) + '-' + data('high', f) + ' F ' +
|
|
|
|
data('condition', f));
|
|
|
|
}
|
|
|
|
}
|
2010-12-28 09:39:12 +03:00
|
|
|
}
|
|
|
|
phantom.exit();
|
|
|
|
}
|