Last active
December 10, 2015 17:01
-
-
Save darrenjaworski/9df54b33813429d03f3c to your computer and use it in GitHub Desktop.
Last 30 days of astronomy pic of the day.
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
<html> | |
<head> | |
<style> | |
.gallery { | |
clear: both; | |
} | |
.apod_img_class { | |
width: 23%; | |
margin: 1%; | |
float: left; | |
} | |
body { | |
margin: auto; | |
max-width: 95%; | |
} | |
iframe { | |
border: none; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="gallery"> | |
</div> | |
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script> | |
var today = new Date(); | |
//for loop to go back a day for a set number of days | |
for (var dayBack = 0; dayBack < 30; dayBack++) { | |
var requestDate = new Date(); | |
requestDate.setDate(today.getDate() - dayBack); | |
var queryString = requestDate.getFullYear()+"-"+parseInt(requestDate.getMonth()+1)+"-"+requestDate.getDate() | |
getImage(queryString); | |
} | |
function getImage(date) { | |
var url = "https://api.nasa.gov/planetary/apod?concept_tags=True&date="+ date +"&hd=True&api_key=NNKOjkoul8n1CH18TWA9gwngW1s1SmjESPjNoUFo"; | |
$.ajax({ | |
url: url, | |
success: handleResult | |
}); | |
function handleResult(result){ | |
if(result.media_type != "video") { | |
$( ".gallery" ).append( "<img class='apod_img_class' src='"+ result.url +"' alt='"+ result.explanation +"'>" ); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment