diff --git a/README.md b/README.md index 255ab44..38609cd 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,104 @@ -# 🚀 Project: Complex NASA API +# 🌌 NASA Astronomy Picture of the Day -### Goal: Use NASA's API to return all of their facility locations (~400). Display the name of the facility, its location, and the weather at the facility currently. +A web application that fetches NASA's Astronomy Picture of the Day (APOD) based on a user-selected date. View stunning space images and videos with detailed descriptions! -### How to submit your code for review: +## ✨ Features -- Fork and clone this repo -- Create a new branch called answer -- Checkout answer branch -- Push to your fork -- Issue a pull request -- Your pull request description should contain the following: - - (1 to 5 no 3) I completed the challenge - - (1 to 5 no 3) I feel good about my code - - Anything specific on which you want feedback! +- 📅 Search by date to find NASA's picture/video from any day +- 🖼️ Display high-definition images from space +- 🎥 Support for video content +- 📝 Detailed explanations for each celestial image +- 📱 Responsive design for mobile and desktop +- 🎨 Beautiful space-themed interface + +## 🚀 How It Works + +1. Enter a date in the format `YYYY-MM-DD` +2. Click "Get Picture" button +3. View the astronomical image or video from that date +4. Read the description to learn more about what you're seeing + +## 🛠️ Technologies Used + +- **HTML5** - Structure +- **CSS3** - Styling and responsive design +- **JavaScript (ES6)** - API calls and DOM manipulation +- **NASA APOD API** - Data source + +## 📂 File Structure + +``` +nasa-api/ +├── index.html # Main HTML structure +├── css/ +│ ├── normalize.css # CSS reset +│ └── style.css # Custom styling +├── js/ +│ └── main.js # API logic and functionality +└── img/ + └── background.jpg # Background image +``` + +## 🔧 Setup Instructions + +1. **Clone the repository** + ```bash + git clone + cd nasa-api + ``` + +2. **Open in browser** + - Simply open `index.html` in your web browser + - No build process or dependencies needed! + +3. **Get your own API key** (optional) + - Visit [NASA API Portal](https://api.nasa.gov/) + - Sign up for a free API key + - Replace the API key in `main.js` + +## 💡 Usage Example -Example: ``` -I completed the challenge: 5 -I feel good about my code: 4 -I'm not sure if my constructors are setup cleanly... +Input: 2024-01-15 +Result: View NASA's featured astronomy content from January 15, 2024 ``` + +## 🌟 API Information + +This project uses NASA's **Astronomy Picture of the Day (APOD)** API: +- **Endpoint**: `https://api.nasa.gov/planetary/apod` +- **Parameters**: date, api_key +- **Response**: Image/video URL, title, and explanation + +## 📱 Responsive Design + +The application is fully responsive with breakpoints for: +- Desktop (default) +- Mobile devices (max-width: 430px) + +## 🎯 Future Enhancements + +- Date picker for easier date selection +- Random date button +- Favorites/bookmarking system +- Share functionality +- Image download option +- Date range browsing + +## 🐛 Known Issues + +- Video playback may vary by browser +- API has rate limits on the demo key + +## 📝 License + +This project is open source and available for educational purposes. + +## 🙏 Credits + +- **NASA API** - Providing free access to space imagery +- **Background image** - Space-themed design elements + +--- + +*Made with 🌟 by Abdirahman Mohamed* diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..e8b365d --- /dev/null +++ b/css/style.css @@ -0,0 +1,42 @@ +* { + box-sizing: border-box; +} + +body { + text-align: center; + background-color: rgb(198, 198, 198); + font-size: 62.5%; + font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; +} + +div ul { + display: flex; + flex-flow: row wrap; + gap: 1em; + list-style: none; + padding: 1%; + +} + +ul li { + border: 1px solid; + width: 15%; + text-align: left; + background-color: wheat; + font-size: 1.7rem; + padding: 1%; + margin: 0 auto; +} + +button { + height: 30px; + border-radius: 5px; +} + +button:hover { + box-shadow: 2px 2px gray; +} + +h1 { + font-size: 3rem; +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..d9a5e29 --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + + + + + + + + Nasa Locations Detector + + + + + + + +

Nasa Complex API

+ + + +
+ +
+ + + + diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..8fc9572 --- /dev/null +++ b/js/main.js @@ -0,0 +1,60 @@ +/** + * Show locations of nasa facility, its name and temperature at that location + * Ryan helped me with this project + */ + +//event listener for the get date button +document.querySelector('button').addEventListener('click', run) + +//create an object to store the data +const facilitiesData = {} + +async function run() { + // const zip = document.querySelector('input').value + + const urlNasa = `https://corsproxy.io/?url=https://data.nasa.gov/docs/legacy/gvk9-iz74.json` + await fetch(urlNasa) + .then(res => res.json()) + .then(data => { + + data.forEach((facility) => { + const state = facility.state + const city = facility.city + const country = facility.country + // console.log(facility) + facilitiesData[facility.center] = { + name: `Name: ${facility.center}`, + city: `City: ${facility.city}`, + state: `State: ${facility.state}`, + country: `Country: ${facility.country}` + } + getWeather(city, state, country, facility.center) + }); + }) + .catch(err => { + console.log(`error ${err}`) + }) +} +async function getWeather(city, state, country, facilityName) { + const apiKey = 'ac7a25cc1fd6223acd06a17e1aeccd7f' + const urlWeather = `https://api.openweathermap.org/data/2.5/weather?q=${city},${state},${country}&appid=${apiKey}&units=imperial` + const listFromDom = document.getElementById("facilities"); + await fetch(urlWeather) + .then(res => res.json()) + .then(weatherData => { + facilitiesData[facilityName].temp = `Temp at location: ${weatherData.main.temp}° F` + // console.log(weatherData) + // console.log(facilitiesData) + + for (const key in facilitiesData) { + if (facilitiesData[key].temp) { + const liElement = document.createElement('li') + liElement.textContent = `${facilitiesData[key].name} ${facilitiesData[key].city} ${facilitiesData[key].state} ${facilitiesData[key].temp}` + listFromDom.appendChild(liElement) + } + } + }) + .catch(err => { + console.log(`error ${err}`) + }) +}