Skip to content

Instantly share code, notes, and snippets.

@andre347
Created May 1, 2020 13:08
Show Gist options
  • Save andre347/0db6de4264086231d854b3ca824f9f76 to your computer and use it in GitHub Desktop.
Save andre347/0db6de4264086231d854b3ca824f9f76 to your computer and use it in GitHub Desktop.
Pablo WDC
const getData = document.getElementById("getData");
let pablosData = [];
async function fetchData() {
const value = document.getElementById("valueForURL").value;
if (value) {
console.log("Getting the data...");
const url = `https://servicios.ine.es/wstempus/js/ES/DATOS_METADATAOPERACION/EPA?g1=115:&&g2=18:454&&g3=3:283910&&g4=141:21387&&p=3&&nult=${value}&&tip=A`;
const resp = await fetch(url);
const json = await resp.json();
json.forEach((item, id) => {
const COD = item.COD;
const Nombre = item.Nombre;
item.Data.forEach((date) => {
const Anyo = date.Anyo;
const Fecha = date.Fecha;
const Valor = date.Valor;
pablosData.push({ COD, Nombre, Anyo, Fecha, Valor });
});
});
console.log(pablosData);
} else {
console.log("Hey no value!!!!");
}
}
getData.addEventListener("click", fetchData);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Hello!</h1>
<input type="number" placeholder="Give me a number!" id="valueForURL" />
<button id="getData">Click here!</button>
<script src="./app.js"></script>
</body>
</html>
@andre347
Copy link
Author

andre347 commented May 1, 2020

Hey! What is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment