Created
May 1, 2020 13:08
-
-
Save andre347/0db6de4264086231d854b3ca824f9f76 to your computer and use it in GitHub Desktop.
Pablo WDC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! What is this?