1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* This program creates an HTTP server that fetches various data from NASA APIs
* and returns a JSON response with a collection of interesting information about today.
* It uses multiple NASA APIs to gather diverse space-related data, including real-time imagery
* and additional interesting data points.
*/
import { DOMParser } from "https://esm.sh/linkedom";
const NASA_API_KEY = 'vYg1cCNLVbcgNemMWuLEjoJsGOGbBXZjZjmwVwuV';
async function fetchNASAData() {
const today = new Date().toISOString().split('T')[0];
// Fetch Astronomy Picture of the Day
const apodResponse = await fetch(`https://api.nasa.gov/planetary/apod?api_key=${NASA_API_KEY}`);
const apodData = await apodResponse.json();
// Fetch latest EPIC image metadata
const epicResponse = await fetch(`https://api.nasa.gov/EPIC/api/natural?api_key=${NASA_API_KEY}`);
const epicData = await epicResponse.json();
const latestEpicImage = epicData[0];
// Fetch Near Earth Objects for today
const neowsResponse = await fetch(`https://api.nasa.gov/neo/rest/v1/feed?start_date=${today}&end_date=${today}&api_key=${NASA_API_KEY}`);
const neowsData = await neowsResponse.json();
// Fetch Mars Weather data (note: this data is not always up-to-date)
const marsWeatherResponse = await fetch(`https://api.nasa.gov/insight_weather/?api_key=${NASA_API_KEY}&feedtype=json&ver=1.0`);
const marsWeatherData = await marsWeatherResponse.json();
// Fetch Earth Observatory Natural Event Tracker (EONET) data
const eonetResponse = await fetch(`https://eonet.gsfc.nasa.gov/api/v3/events`);
const eonetData = await eonetResponse.json();
// Fetch ISS Current Location
const issResponse = await fetch('http://api.open-notify.org/iss-now.json');
const issData = await issResponse.json();
// Fetch NASA Image and Video Library data
const nasaLibraryResponse = await fetch(`https://images-api.nasa.gov/search?q=space&media_type=image`);
const nasaLibraryData = await nasaLibraryResponse.json();
// Fetch TLE (Two-Line Element) data for satellites
const tleResponse = await fetch('https://www.celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=json');
const tleData = await tleResponse.json();
return {
date: today,
astronomyPictureOfTheDay: {
title: apodData.title,
explanation: apodData.explanation,
url: apodData.url,
mediaType: apodData.media_type,
},
earthPolychromaticImagingCamera: {
date: latestEpicImage.date,
caption: latestEpicImage.caption,
imageUrl: `https://epic.gsfc.nasa.gov/archive/natural/${latestEpicImage.date.split(' ')[0].replace(/-/g, '/')}/png/${latestEpicImage.image}.png`,
},
nearEarthObjects: {
totalObjectsToday: neowsData.element_count,
potentiallyHazardousAsteroids: neowsData.near_earth_objects[today].filter(obj => obj.is_potentially_hazardous_asteroid).length,
closestObject: neowsData.near_earth_objects[today].reduce((closest, current) =>
(parseFloat(current.close_approach_data[0].miss_distance.kilometers) < parseFloat(closest.close_approach_data[0].miss_distance.kilometers)) ? current : closest
),
},
marsWeather: marsWeatherData.sol_keys ? {
solKeys: marsWeatherData.sol_keys,
latestSol: marsWeatherData[marsWeatherData.sol_keys[marsWeatherData.sol_keys.length - 1]],
} : "Mars weather data currently unavailable",
earthEvents: {
totalEvents: eonetData.events.length,
recentEvents: eonetData.events.slice(0, 5).map(event => ({
title: event.title,
type: event.categories[0].title,
date: event.geometry[0].date
}))
},
internationalSpaceStation: {
currentLocation: {
latitude: issData.iss_position.latitude,
longitude: issData.iss_position.longitude,
},
timestamp: new Date(issData.timestamp * 1000).toISOString()
},
nasaImageLibrary: {
recentImages: nasaLibraryData.collection.items.slice(0, 5).map(item => ({
title: item.data[0].title,
description: item.data[0].description,
url: item.links[0].href
}))
},
satelliteData: {
totalTracked: tleData.length,
recentSatellites: tleData.slice(0, 5).map(sat => ({
name: sat.OBJECT_NAME,
noradCatId: sat.NORAD_CAT_ID,
objectType: sat.OBJECT_TYPE
}))