Skip to content

Instantly share code, notes, and snippets.

@bbrochier
Created February 22, 2017 16:44
Show Gist options
  • Save bbrochier/44e8e45fdffa479a51cb0ce7b46a17a7 to your computer and use it in GitHub Desktop.
Save bbrochier/44e8e45fdffa479a51cb0ce7b46a17a7 to your computer and use it in GitHub Desktop.
Vuejs method for xml parser with jquery
fetchLive: function() {
var self = this;
$.when(
$.ajax({
url: 'http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=val-d-isere&v=2',
success: function(data) {
var $xml = $(data);
//remontees
self.valdisere.remontees.total = parseInt($xml.find('REMONTEES').attr('total_periode'), 10);
self.valdisere.remontees.opened = parseInt($xml.find('REMONTEES').attr('ouvertes_previsions'), 10);
//pistes
self.valdisere.pistes.total = parseInt($xml.find('SKI_ALPIN').attr('total_periode'), 10);
self.valdisere.pistes.opened = parseInt($xml.find('SKI_ALPIN').attr('ouvertes_previsions'), 10);
},
error: function() {
self.infolive = false; //hide infolive barre
}
}),
$.ajax({
url: 'http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=tignes&v=2',
success: function(data) {
var $xml = $(data);
//remontees
self.tignes.remontees.total = parseInt($xml.find('REMONTEES').attr('total_periode'), 10);
self.tignes.remontees.opened = parseInt($xml.find('REMONTEES').attr('ouvertes_previsions'), 10);
//piste
self.tignes.pistes.total = parseInt($xml.find('SKI_ALPIN').attr('total_periode'), 10);
self.tignes.pistes.opened = parseInt($xml.find('SKI_ALPIN').attr('ouvertes_previsions'), 10);
//weater tignes
var tignesData = $xml.find('ZONE[nom="Tignes Lac"]');
self.tignes.temperature.am = tignesData.find('TEMPERATURE').text();
self.tignes.temperature.pm = tignesData.find('TEMPERATURE_APM').text();
self.tignes.weather.am = tignesData.find('CIEL_ID').text();
self.tignes.weather.pm = tignesData.find('CIEL_ID_APM').text();
self.tignes.snow.total = tignesData.find('CUMUL').text();
self.tignes.snow.fresh = tignesData.find('NEIGE').text();
//weather grande motte
var motteData = $xml.find('ZONE[nom="Gde Motte"]');
self.motte.temperature.am = motteData.find('TEMPERATURE').text();
self.motte.temperature.pm = motteData.find('TEMPERATURE_APM').text();
self.motte.weather.am = motteData.find('CIEL_ID').text();
self.motte.weather.pm = motteData.find('CIEL_ID_APM').text();
self.motte.snow.total = motteData.find('CUMUL').text();
self.motte.snow.fresh = motteData.find('NEIGE').text();
self.motte.avalanches.risk = motteData.find('VALRISQUE').text();
},
error: function() {
self.infolive = false; //hide infolive barre
}
})
).then(function() {
self.initSliderLive();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment