-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: master
Are you sure you want to change the base?
Miguel curiosity #52
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
] | ||
} |
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(); | ||
xmlHttp.open("GET", url, true); | ||
xmlHttp.send(); | ||
xmlHttp.onreadystatechange = function() { | ||
|
||
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { | ||
console.log("respuesta"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
resolve (JSON.parse(xmlHttp.responseText)); | ||
} | ||
else if (xmlHttp.readyState === 4 && xmlHttp.status === 404) { | ||
console.error("ERROR! 404"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
reject (JSON.parse(xmlHttp.responseText)); | ||
} | ||
}; | ||
|
||
|
||
}); | ||
} | ||
|
||
|
||
let sun = 2047; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esta recursividad deberia ser dentro de la función |
||
console.log("currentValue:", currentValue.photos); | ||
sun -=1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Puedes hacer |
||
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++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No tienes justficación para este |
||
// 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); | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
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> |
There was a problem hiding this comment.
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