Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
UO291047 authored Nov 23, 2023
1 parent ea6747c commit c8b52d6
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
12 changes: 12 additions & 0 deletions agenda.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<link rel="stylesheet" type="text/css" href="estilo.css" />
<link rel="stylesheet" type="text/css" href="layout.css" />
<link rel="icon" href="multimedia/imagenes/favicon.ico"/>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"></script>
<script src="js/agenda.js"></script>

</head>

Expand All @@ -34,5 +38,13 @@ <h1>Escritorio Virtual</h1>

<h2>Agenda</h2>

<script>
const agenda = new Agenda();
</script>

<footer>
<button onclick="agenda.verXML()">Obtener datos F1</button>
</footer>

</body>
</html>
56 changes: 56 additions & 0 deletions js/agenda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Agenda{

constructor(){
this.url = "http://ergast.com/api/f1/current";
this.last_api_call = null;
this.las_api_result = null;
}

cargarDatos(){
$.ajax({
dataType: "xml",
url: this.url,
method: 'GET',
success: function(datos){
//$("h5").text((new XMLSerializer()).serializeToString(datos));

//Presentación de los datos contenidos en XML
$.each($('Race',datos), function(item){
var stringDatos = "<ul><li>Carrera: " + $('RaceName',item).text() + "</li>";
stringDatos += "<li>Circuito: " + $('CircuitName',item).text() + "</li>";
stringDatos += "<li>Coordenadas: [" + $('Location',item).attr('lat') + "," + $('Location',datos).attr('long') + "]</li>";
stringDatos += "<li>Fecha: " + $('Date',item).text() + "</li>";
stringDatos += "<li>Hora: " + $('Time',item).text() + "</li>";

$("pre").html(stringDatos);
});

},
error:function(){
$("h4").remove();
//$("h5").remove();
$("pre").remove();
}
});
}

crearElemento(tipoElemento, texto, insertarAntesDe){
// Crea un nuevo elemento modificando el árbol DOM
// El elemnto creado es de 'tipoElemento' con un 'texto'
// El elemnto se coloca antes del elemnto 'insertarAntesDe'
var elemento = document.createElement(tipoElemento);
elemento.innerHTML = texto;
$(insertarAntesDe).before(elemento);
}

verXML(){

//Muestra el archivo XML recibido
this.crearElemento("h4", "Datos", "footer")
//this.crearElemento("h5", "", "h4")
this.crearElemento("pre","","footer"); // Crea un elemento con DOM para el string con JSON
this.cargarDatos();
$("button").attr("disabled","disabled");
}

}
63 changes: 63 additions & 0 deletions js/ejemploSalida.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="/schemas/mrd-1.5.xsl"?>
<MRData xmlns="http://ergast.com/mrd/1.5" series="f1" url="http://ergast.com/api/f1/current" limit="30" offset="0" total="22">
<RaceTable season="2023">
<Race season="2023" round="1" url="https://en.wikipedia.org/wiki/2023_Bahrain_Grand_Prix">
<RaceName>Bahrain Grand Prix</RaceName>
<Circuit circuitId="bahrain" url="http://en.wikipedia.org/wiki/Bahrain_International_Circuit">
<CircuitName>Bahrain International Circuit</CircuitName>
<Location lat="26.0325" long="50.5106">
<Locality>Sakhir</Locality>
<Country>Bahrain</Country>
</Location>
</Circuit>
<Date>2023-03-05</Date>
<Time>15:00:00Z</Time>
<FirstPractice>
<Date>2023-03-03</Date>
<Time>11:30:00Z</Time>
</FirstPractice>
<SecondPractice>
<Date>2023-03-03</Date>
<Time>15:00:00Z</Time>
</SecondPractice>
<ThirdPractice>
<Date>2023-03-04</Date>
<Time>11:30:00Z</Time>
</ThirdPractice>
<Qualifying>
<Date>2023-03-04</Date>
<Time>15:00:00Z</Time>
</Qualifying>
</Race>
<!-- ... (resto de las carreras) ... -->
<Race season="2023" round="22" url="https://en.wikipedia.org/wiki/2023_Abu_Dhabi_Grand_Prix">
<RaceName>Abu Dhabi Grand Prix</RaceName>
<Circuit circuitId="yas_marina" url="http://en.wikipedia.org/wiki/Yas_Marina_Circuit">
<CircuitName>Yas Marina Circuit</CircuitName>
<Location lat="24.4672" long="54.6031">
<Locality>Abu Dhabi</Locality>
<Country>UAE</Country>
</Location>
</Circuit>
<Date>2023-11-26</Date>
<Time>13:00:00Z</Time>
<FirstPractice>
<Date>2023-11-24</Date>
<Time>09:30:00Z</Time>
</FirstPractice>
<SecondPractice>
<Date>2023-11-24</Date>
<Time>13:00:00Z</Time>
</SecondPractice>
<ThirdPractice>
<Date>2023-11-25</Date>
<Time>10:30:00Z</Time>
</ThirdPractice>
<Qualifying>
<Date>2023-11-25</Date>
<Time>14:00:00Z</Time>
</Qualifying>
</Race>
</RaceTable>
</MRData>
8 changes: 4 additions & 4 deletions js/pais.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ class Pais {
stringDatos += "<li>Temperatura máxima: " + datos.list[0].main.temp_max + " grados Celsius</li>";
stringDatos += "<li>Temperatura mínima: " + datos.list[0].main.temp_min + " grados Celsius</li>";
stringDatos += "<li>Humedad: " + datos.list[0].main.humidity + " %</li>";
stringDatos += "<li> <img src=https://openweathermap.org/img/wn/" + datos.list[0].weather[0].icon + "@2x.png/> </li>";
stringDatos += "<li> <img src=https://openweathermap.org/img/wn/" + datos.list[0].weather[0].icon + "@2x.png> </li>";

$("pre").html(stringDatos);
},
error:function(){
$("h3").html("¡Tenemos problemas! No puedo obtener JSON de <a href='http://openweathermap.org'>OpenWeatherMap</a>");
$("h4").remove();
$("pre").remove();
}
Expand All @@ -91,8 +90,9 @@ class Pais {
//https://api.openweathermap.org/data/2.5/forecast?lat=-6.17221&lon=35.73947&appid=dff06432f9d5b3e7c70f9a5f75d2615d&units=metric&lang=es
this.correcto = "¡Todo correcto! JSON recibido de <a href='http://openweathermap.org'>OpenWeatherMap</a>";

//Muestra el archivo JSON recibido
this.crearElemento("pre","Datos","p"); // Crea un elemento con DOM para el string con JSON
//Muestra el archivo JSON recibido
this.crearElemento("h4", "Datos", "footer")
this.crearElemento("pre","","footer"); // Crea un elemento con DOM para el string con JSON
this.cargarDatos();
}

Expand Down
2 changes: 2 additions & 0 deletions meteorologia.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ <h2>Meteorología</h2>
pais.verJSON();
</script>

<footer></footer>

</body>
</html>

0 comments on commit c8b52d6

Please sign in to comment.