Skip to content

Commit

Permalink
tweak description field (summary is sometimes null)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand committed Jul 8, 2024
1 parent 7e1994f commit 8170945
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions learning_resources/etl/mitpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ def parse_resource_url(resource_data: dict) -> str:
return urljoin(BASE_URL, resource_data["attributes"]["path"]["alias"])


def parse_description(resource_data: dict) -> str:
"""
Return the description for the resource. Use summary field if not blank.
Args:
resource_data: course or program data
Returns:
str: description for the resource
"""
summary = resource_data["attributes"]["field_featured_course_summary"]
if summary:
return clean_data(summary)
return clean_data(resource_data["attributes"]["body"]["processed"])


def _transform_runs(resource_data: dict) -> list[dict]:
"""
Transform course/program runs into our normalized data structure
Expand Down Expand Up @@ -288,9 +304,7 @@ def transform_course(resource_data: dict) -> dict or None:
"title": resource_data["attributes"]["title"],
"url": parse_resource_url(resource_data),
"image": parse_image(resource_data),
"description": clean_data(
resource_data["attributes"]["field_featured_course_summary"]
),
"description": parse_description(resource_data),
"full_description": clean_data(
resource_data["attributes"]["body"]["processed"]
),
Expand Down Expand Up @@ -330,9 +344,7 @@ def transform_program(resource_data: dict) -> dict:
"title": resource_data["attributes"]["title"],
"url": parse_resource_url(resource_data),
"image": parse_image(resource_data),
"description": clean_data(
resource_data["attributes"]["field_featured_course_summary"]
),
"description": parse_description(resource_data),
"full_description": clean_data(
resource_data["attributes"]["body"]["processed"]
),
Expand Down

0 comments on commit 8170945

Please sign in to comment.