Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fetch Disney character appearances for Disneyland California using themeparks library
var ThemeParks = require("themeparks");
var MagicKingdom = new ThemeParks.Parks.DisneylandResortMagicKingdom();
// https://api.wdpro.disney.go.com/bulk-service/snapshot/DLR-mobile-character-appearances
// for reference: above URL requests these two URLs at the same time (hense the "bulk-service")
// https://api.wdpro.disney.go.com/global-pool-override-B/bulk-service/snapshot/DLR-mobile-dl-character-appearances
// https://api.wdpro.disney.go.com/global-pool-override-B/bulk-service/snapshot/DLR-mobile-ca-character-appearances
MagicKingdom.GetAPIUrl({
url: "https://api.wdpro.disney.go.com/bulk-service/snapshot/DLR-mobile-character-appearances"
}).then(function(characterData) {
// because we're using the bulk-service, we doing to get multiple responses, so here we'll loop over them
for (var i = 0, result; result = characterData.responses[i++];) {
// figure out which park this was a response for...
var park_id;
if (result.finalUrl.indexOf("DLR-mobile-dl-character-appearances") >= 0) {
// disneyland response
park_id = "dl";
} else if (result.finalUrl.indexOf("DLR-mobile-ca-character-appearances") >= 0) {
// california adventure response
park_id = "ca"
}
// skip if we don't recognise this park
if (!park_id) continue;
// parse the JSON response
var body = result.body;
try {
body = JSON.parse(body);
} catch (e) {
console.error("Failed to parse JSON response from bulk-service: " + e);
}
// debug view the data structure
//console.log(JSON.stringify(body, null, 2));
for (var j = 0, character; character = body.entries[j++];) {
// sort all the times
var times = [];
for (var k = 0, time; time = character.appearances[k++];) {
times.push({
start: time.startTime,
end: time.endTime
});
}
console.log({
name: character.character.name,
description: character.character.descriptions ? character.character.descriptions.shortDescriptionMobile.text : "",
times: times,
park: park_id
});
}
}
}, console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.