Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
126 changes: 126 additions & 0 deletions complex-nasa-api/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: 'Poppins', sans-serif;
font-weight: 300;
color: white;
background-color: #000;
}

h1, h2, h3, h4 {
font-family: 'Orbitron', sans-serif;
font-weight: 700;
text-transform: uppercase;
color: #ffcc00;
}

header {
background-color: #1a1a2e;
color: white;
padding: 10px 20px;
border-bottom: 2px solid #ccc;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
}

nav {
display: flex;
justify-content: space-between;
align-items: center;
}

nav .logo {
font-size: 24px;
font-weight: bold;
display: flex;
align-items: center;
gap: 10px;
}

nav ul {
display: flex;
list-style: none;
}

nav li {
margin: 0 15px;
font-size: 18px;
cursor: pointer;
display: flex;
align-items: center;
gap: 5px;
color: white;
transition: color 0.3s ease;
}

nav li:hover {
color: #ffcc00;
}

main {
text-align: center;
padding: 40px 20px;
background-image: url('starry-background.png');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}

main h1 {
font-size: 36px;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 3px;
color: #ffcc00;
margin-bottom: 10px;
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* Subtle shadow */
}

main h4 {
font-size: 18px;
margin-bottom: 20px;
color: #ccc;
}

input[type="text"] {
width: 60%;
padding: 10px;
margin-bottom: 20px;
border: 2px solid #ffcc00;
border-radius: 5px;
background-color: #000;
color: white;
}

button {
background-color: #1a1a2e;
color: white;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #ffcc00;
color: #000;
}

img {
max-width: 75%;
margin: 20px auto;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.7);
}

iframe {
width: 80%;
height: 100px;
margin: 20px auto;
border-radius: 10px;
}
45 changes: 45 additions & 0 deletions complex-nasa-api/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="This is where your description goes">
<meta name="keywords" content="one, two, three">

<title>Nasa Complex Api</title>

<!-- external CSS link -->
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Poppins:wght@300;400;500;700&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<header>
<nav>
<div class="logo">
<i class="fas fa-rocket"></i> NASA Explorer
</div>
<ul>
<li><i class="fas fa-home"></i> Home</li>
<li><i class="fas fa-info-circle"></i> About</li>
<li><i class="fas fa-envelope"></i> Contact</li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Which date?</h1>
<h4></h4>
<input type="text" name="date" placeholder="YYYY-MM-DD" required>
<button type="button" name="button">Get Picture</button>
</section>
<section id="summary"></section>
<section>
<h2>Name</h2>
<img src="" alt="">
<iframe src="" frameborder="0"></iframe>
<h3>Description</h3>
</section>
</main>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions complex-nasa-api/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
document.querySelector('button').addEventListener('click', getNasaDate)

function getNasaDate(){

document.querySelector('iframe').src = ''
document.querySelector('img').src = ''

const nasaDate = document.querySelector('input').value

fetch(`https://api.nasa.gov/planetary/apod?api_key=5zjGk9dwqh6KrWSRQCqbV0RIct5n3OJKMqG0lhNn&date=${nasaDate}`)
.then(res => res.json())
.then(data => {
console.log(data)
//display our data
document.querySelector('h2').innerText = data.title
// document.querySelector('img').src = data.hdurl
document.querySelector('h3').innerText = data.explanation
if(data.media_type === 'image'){ //media_type is a property key of data (our JSON) and 'image' is its defined property value (check console)
document.querySelector('img').src = data.hdurl
}else{
document.querySelector('iframe').src = data.hdurl
}

// Extract a topic to search on Wikipedia ---> can't figure it out so Astronomy will do
const topic = 'Astronomy' //data.query.search[0].title

//data.title.trim() || data.explanation.split(' ').slice(0, 5).join(' ') || 'Astronomy'// First 5 words from the explanation
//.split(' ')[0]; // Example: Use the first word of the title as the topic
getWikipediaData(topic);
})
.catch(err => {
console.log(`error ${err}`)
})
}

function getWikipediaData(query) {
// Fetch data from Wikipedia API
const wikipediaUrl = `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(query)}`

//`https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(query.trim())}&format=json&origin=*`;

fetch(wikipediaUrl)
.then(res => res.json())
.then(data => {
console.log(data);

// Display Wikipedia data
const section = document.querySelector('#summary');
section.innerHTML = ''
const wikiInfo = document.createElement('p');
wikiInfo.innerHTML = `
<strong>Wikipedia Summary:</strong><br>
<strong>Title:</strong> ${data.title}<br>
<strong>Description:</strong> ${data.extract}<br>
<a href="${data.content_urls.desktop.page}" target="_blank">Read more on Wikipedia</a>
`;
section.appendChild(wikiInfo);
})
.catch(err => {
console.error(`error ${err}`);
});
}