└── Astro /Astro: -------------------------------------------------------------------------------- 1 | import requests 2 | import datetime 3 | 4 | # Get current date in the format required by the API 5 | current_date = datetime.date.today().isoformat() 6 | 7 | # API endpoint 8 | url = f"https://api.nasa.gov/neo/rest/v1/feed?start_date={current_date}&end_date={current_date}&api_key=your_api_key" 9 | 10 | # Make a GET request to the API 11 | response = requests.get(url) 12 | 13 | # Parse JSON response 14 | data = response.json() 15 | 16 | # Extract asteroid data 17 | asteroids = data['near_earth_objects'][current_date] 18 | 19 | # Initialize variables to store closest asteroid data 20 | closest_asteroid = None 21 | min_distance = float('inf') 22 | 23 | # Find the closest asteroid 24 | for asteroid in asteroids: 25 | distance = asteroid['close_approach_data'][0]['miss_distance']['kilometers'] 26 | if distance < min_distance: 27 | min_distance = distance 28 | closest_asteroid = asteroid 29 | 30 | # Display closest asteroid information 31 | print(f"The closest asteroid to Earth today is {closest_asteroid['name']} with a distance of {min_distance} kilometers.") 32 | --------------------------------------------------------------------------------