xxxxxxxxxx
/**
* Multi JSON Loading (v1.0)
* GoToLoop (2018-Dec-05)
* https://Discourse.Processing.org/t/how-do-i-load-multiple-json-urls/6150/16
* https://OpenProcessing.org/sketch/639946
*/
"use strict";
const HTTP = 'https://', SITE = 'Query.YahooApis.com/',
DIR = 'v1/public/', FILE = 'yql',
P1 = '?q=select * from weather.forecast where woeid in ',
P2 = '(select woeid from geo.places(1) where text="',
P3 = ', il")&format=json&env=store://datatables.org/alltableswithkeys',
URI = HTTP + SITE + DIR + FILE + P1 + P2,
CITIES = Object.freeze([
'chicago', 'aurora', 'joliet', 'naperville',
'rockford','springfield', 'elgin', 'peoria'
]),
jsons = Array(CITIES.length), casts = Array(CITIES.length);
function preload() {
for (let i = 0; i < CITIES.length; ++i)
jsons[i] = loadJSON(URI + CITIES[i] + P3);
}
function setup() {
grabForecasts();
logForecasts();
}
function grabForecasts() {
for (let i = 0; i < CITIES.length; ++i)
casts[i] = jsons[i].query.results.channel.item.forecast;
}
function logForecasts() {
for (let i = 0; i < CITIES.length; ++i) {
console.info(CITIES[i] + ':');
console.table(casts[i]);
}
}