Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miguel curiosity #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added miguelGarcia/public/nasa/.DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions miguelGarcia/public/nasa/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Iniciar programa",
"program": "${workspaceFolder}/async.js"
}
]
}
86 changes: 86 additions & 0 deletions miguelGarcia/public/nasa/curiosity2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

function NasaRequest(url,sun,limit,frecuency) {

return new Promise(function(resolve,reject){

let xmlHttp = new XMLHttpRequest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto es una constante ;-) Documentación

xmlHttp.open("GET", url, true);
xmlHttp.send();
xmlHttp.onreadystatechange = function() {

if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
console.log("respuesta");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ console.log... perdido

resolve (JSON.parse(xmlHttp.responseText));
}
else if (xmlHttp.readyState === 4 && xmlHttp.status === 404) {
console.error("ERROR! 404");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ console.log... perdido

reject (JSON.parse(xmlHttp.responseText));
}
};


});
}


let sun = 2047;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto debería evitarse... no deberías tener los valores de forma global

let frecuency = 1000;
async function init() {

const token = "UtXjt0H5jUOdg7OzsNhKrqYgGLUwRu3yC688M13w";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Token expuesto...

let limit = false;
let url = `https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=${sun}&api_key=${token}`

const currentValue = await NasaRequest(url,frecuency);
if (currentValue.length === 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta recursividad deberia ser dentro de la función NasaRequest. Ver solución

console.log("currentValue:", currentValue.photos);
sun -=1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puedes hacer sun--;

init()

}
else {
console.log("currentValue:", currentValue.photos);
pintarfotos(currentValue);
}
}

init();



divRow = document.querySelector('#cartas');
function pintarfotos(currentValue){

for (i = 0 ; i < currentValue.photos.length ; i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tienes justficación para este for, el contexto te deja usar un forEach

// crear tarjeta
card = document.createElement('div');
card.setAttribute('class','card text-center p-1 bg-warning m-3 border-warning');
cardTitle = document.createTextNode('Sol: ' + currentValue.photos[i].sol);
cameraName = document.createTextNode(currentValue.photos[i].camera.full_name);
id = document.createTextNode('Id: ' + currentValue.photos[i].id);
h6 = document.createElement('h6');
h6.appendChild(cameraName);
h5 = document.createElement('h5');
h5.appendChild(cardTitle);
h6i = document.createElement('h6');
h6i.appendChild(id);

cardImg = document.createElement('img');
cardImg.setAttribute('class','card-img-top');
cardImg.setAttribute('src',currentValue.photos[i].img_src);
card.appendChild(cardImg);
card.appendChild(h5);
card.appendChild(h6);
card.appendChild(h6i);
divCol = document.createElement('div');
divCol.setAttribute('class','col-4');
divCol.appendChild(card);
divRow.appendChild(divCol);






}
}
Binary file added miguelGarcia/public/nasa/iconcurio.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions miguelGarcia/public/nasa/index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>Api Nasa</title>
</head>
<body>

<div class="container">
<div class=" row bg-warning align-items-center justify-content-center p-3">
<div class="col-3">
<img class="rounded" src="iconcurio.jpeg" width=100px height="100" alt="">
</div>
<div class="col-9">
<h1 class= "display-4">Curiosity photos</h1>
</div>
</div>
<div class="row justify-content-around">


</div>
<div id = "cartas" class="row justify-content-around"></div>
</div>



<script src="curiosity2.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>