Update Exploring Near Earth Objects project and add Meme Generator project

This commit is contained in:
2026-01-03 21:55:24 -08:00
parent 9a4c3f7854
commit 155f0c9c6d
36 changed files with 754 additions and 65 deletions

View File

@@ -12,9 +12,9 @@ line, and uses the resulting collections to build an `NEODatabase`.
You'll edit this file in Task 2.
"""
import csv
import json
from models import NearEarthObject, CloseApproach
@@ -24,8 +24,16 @@ def load_neos(neo_csv_path):
:param neo_csv_path: A path to a CSV file containing data about near-Earth objects.
:return: A collection of `NearEarthObject`s.
"""
# TODO: Load NEO data from the given CSV file.
return ()
neos = []
with open(neo_csv_path, "r") as csv_file:
reader = csv.reader(csv_file)
next(reader)
for row in reader:
neo = NearEarthObject(
designation=row[3], name=row[4], diameter=row[15], hazardous=row[7]
)
neos.append(neo)
return neos
def load_approaches(cad_json_path):
@@ -34,5 +42,17 @@ def load_approaches(cad_json_path):
:param cad_json_path: A path to a JSON file containing data about close approaches.
:return: A collection of `CloseApproach`es.
"""
# TODO: Load close approach data from the given JSON file.
return ()
approaches = []
with open(cad_json_path, "r") as json_file:
cad = json.load(json_file)
for item in cad["data"]:
# 0: pdes, 3: cd, 4: dist, 7: v_rel
approach = CloseApproach(
designation=item[0],
time=item[3],
distance=float(item[4]),
velocity=float(item[7]),
)
approaches.append(approach)
return approaches