Public
Edited
Dec 20, 2023
Insert cell
Insert cell
Insert cell
Insert cell
description = data?.location["area-description"]
Insert cell
series = {
if (!data) return;
const parameters = data.parameters;
const timeStart = data["time-layout"]["start-valid-time"];
const timeEnd = data["time-layout"]["end-valid-time"];
const tempLow = parameters.temperature[0].value;
const tempHigh = parameters.temperature[2].value;
const precipProbability = parameters["probability-of-precipitation"].value;

return Array.from({ length: timeStart.length }).map((_, index) => ({
startTime: new Date(timeStart[index]),
endTime: new Date(timeEnd[index]),
tempLow: +tempLow[index],
tempHigh: +tempHigh[index],
precipProb: +precipProbability[index]
}));
}
Insert cell
data = xmlParsed.dwml.data
Insert cell
xmlParsed = xml2json(xmlDoc)
Insert cell
// code credit: https://stackoverflow.com/a/20861541
function xml2json(xml) {
try {
var obj = {};
if (xml.children.length > 0) {
for (var i = 0; i < xml.children.length; i++) {
var item = xml.children.item(i);
var nodeName = item.nodeName;

if (typeof obj[nodeName] == "undefined") {
obj[nodeName] = xml2json(item);
} else {
if (typeof obj[nodeName].push == "undefined") {
var old = obj[nodeName];

obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(xml2json(item));
}
}
} else {
obj = xml.textContent;
}
return obj;
} catch (e) {
console.log(e.message);
}
}
Insert cell
xmlDoc = parser.parseFromString(xmlString, "text/xml")
Insert cell
parser = new DOMParser()
Insert cell
xmlString = await fetch(url).then((response) => response.text())
Insert cell
url = `${baseURI}/${path}?${params}`
Insert cell
params = `lat=${lat}&lon=${lon}&FcstType=digitalDWML`
Insert cell
lat = 37.81
Insert cell
lon = -122.25
Insert cell
path = "MapClick.php"
Insert cell
baseURI = "https://forecast.weather.gov"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more