Skip to content

Commit

Permalink
courses field from MITPE API will be pipe-delimited list of titles
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand committed Aug 9, 2024
1 parent fe18792 commit cd2fa81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions learning_resources/etl/mitpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def clean_title(title: str) -> str:
Returns:
str: cleaned title
"""
return html.unescape(title)
return html.unescape(title.strip())


def parse_description(resource_data: dict) -> str:
Expand Down Expand Up @@ -297,10 +297,10 @@ def transform_program(resource_data: dict) -> dict or None:
"url": parse_resource_url(resource_data),
"image": parse_image(resource_data),
"description": parse_description(resource_data),
"course_ids": [
course_id
for course_id in resource_data["courses"].split("|")
if course_id
"course_titles": [
course_title
for course_title in resource_data["courses"].split("|")
if course_title
],
"learning_format": transform_format(resource_data["learning_format"]),
"published": True,
Expand All @@ -318,13 +318,15 @@ def transform_program_courses(programs: list[dict], courses_data: list[dict]):
programs(list[dict]): list of program data
courses_data(list[dict]): list of course data
"""
course_dict = {course["readable_id"]: course for course in courses_data}
course_dict = {course["title"]: course for course in courses_data}
for program in programs:
course_ids = program.pop("course_ids", [])
course_titles = [
clean_title(title) for title in program.pop("course_titles", [])
]
program["courses"] = [
copy.deepcopy(course_dict[course_id])
for course_id in course_ids
if course_id in course_dict
copy.deepcopy(course_dict[course_title])
for course_title in course_titles
if course_title in course_dict
]


Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/mitpe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"instructors": [{"full_name": ""}, {"full_name": "Brian Anthony"}],
}
],
"courses": [EXPECTED_COURSES[0]],
"courses": [EXPECTED_COURSES[0], EXPECTED_COURSES[1]],
}
]

Expand Down
2 changes: 1 addition & 1 deletion test_json/professional_ed/professional_ed_resources_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"topics": "Technology: Technology Innovation",
"image__src": "/sites/default/files/2020-08/Smart%20Manufacturing.jpg",
"image__alt": "Smart Manufacturing Header Image",
"courses": "a44c8b47-552c-45f9-b91b-854172201889",
"courses": "Comunicação Persuasiva: Pensamento Crítico para Aprimorar a Mensagem (Portuguese)|Design-Thinking and Innovation for Technical Leaders",
"start_date": "2023-07-06",
"end_date": "2023-09-14",
"enrollment_end_date": "2023-07-06",
Expand Down

0 comments on commit cd2fa81

Please sign in to comment.