I will provide documentation on how I retrieved the request of
constellations and
kepler objects from https://api.nasa.gov/
here.
import os
import requests
# Function to fetch data from NASA Exoplanet Archive API
def fetch_nasa_exoplanet_data(api_key):
try:
url = f"https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=cumulative&select=kepid,kepoi_name,kepler_name,koi_disposition,koi_pdisposition,koi_score,koi_fpflag_nt&format=json&api_key={api_key}"
response = requests.get(url)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Failed to fetch data from NASA: {e}")
return []
# Function to classify stars and exoplanets
def classify_objects(data):
classifications = []
for obj in data:
classification = {
"kepid": obj.get("kepid", "Unknown"),
"kepoi_name": obj.get("kepoi_name", "Unknown"),
"kepler_name": obj.get("kepler_name", "Unknown"),
"koi_disposition": obj.get("koi_disposition", "Unknown"),
"koi_pdisposition": obj.get("koi_pdisposition", "Unknown"),
"koi_score": obj.get("koi_score", "Unknown"),
"koi_fpflag_nt": obj.get("koi_fpflag_nt", "Unknown")
}
classifications.append(classification)
return classifications
# Main function
def main():
nasa_api_key = os.getenv("NASA_API_KEY")
combined_data = fetch_nasa_exoplanet_data(nasa_api_key)
classifications = classify_objects(combined_data)
output_file = "REDACTED\\REDACTED.txt"
with open(output_file, "w") as file:
for classification in classifications:
file.write(f"{classification}\\n")
print(f"Output written to {output_file}")
if __name__ == "__main__":
main()