This demonstration project showcases how to utilize the MIT Learn API. It specifically focuses on extracting MIT OpenCourseWare courses' metadata and creating a CSV file for export to OER Commons, aligning with their specific requirements.
SECTIONS
- Build the container:
docker compose build
- Start the container:
docker compose run --rm app
To generate a JSON file containing complete API data:
docker compose run --rm app --create_json
To create a CSV file from the local JSON file:
docker compose run --rm app --create_csv --source=json
The output files, whether in CSV or JSON format, are stored within the private/output
directory relative to the current working directory from which the command is executed.
Therefore, the above commands will generate private/output/ocw_oer_export.csv
or private/output/ocw_api_data.json
in the current working directory.
If you want to change this, you will not only have to change the output_path
in the function (create_csv
or create_json
) but also have to change the mapping in docker-compose.yml
.
By default, this project uses MIT Learn's Production API, as given in ocw_oer_export/config.py
.
To use the RC API or local, create an environment file, .env
in the project's root directory and add the relevant base URL:
e.g., API_BASE_URL=https://api.rc.learn.mit.edu
or API_BASE_URL=http://localhost:8063
For successful execution and correct output, ensure the MIT Learn's API contains the following fields:
title
, url
, runs: level
, description
, topics
, runs: instructors
, runs: semester
, runs: year
, course_feature
Additionally, the mapping_files
should be up-to-date. If new topics are added in OCW without corresponding mappings in ocw_oer_export/mapping_files/ocw_topic_to_oer_subject.csv
, this will lead to null
entries for those topics in the CSV (CR_SUBJECT
). In addition to that, make sure fm_keywords_exports.csv
is also present.
To run unit tests:
docker run --rm ocw_oer_export python -m unittest discover -s tests
To ensure commits to GitHub are safe, first install pre-commit:
pip install pre-commit
pre-commit install
Running pre-commit can confirm your commit is safe to be pushed to GitHub and correctly formatted:
pre-commit run --all-files