Load Courses

Load course data from JSON into database.

This Django management command reads course data from a JSON file and creates/updates database records for courses and their related entities.

JSON Schema

The JSON file should follow this schema:

{
    "Department Name": [
        {
            "course_name": str,          // Full title of the course
            "description": str,          // Course description text
            "course_acronyms": [str],    // Course codes (e.g. ["COSC-111"])
            "departments": {             // Department names mapped to URLs
                str: str                 // e.g. {"Computer Science": "https://..."}
            },

            // Optional fields
            "course_url": str,          // URL to course page
            "divisions": [str],         // Academic division names
            "keywords": [str],          // Course topic keywords
            "offerings": {              // Term offerings mapped to URLs
                str: str                 // e.g. {"Spring 2024": "https://..."}
            },
            "section_information": {     // Section data keyed by section number
                str: {                   // Contains professor, time, location info
                    "professor_name": str,
                    "professor_link": str,
                    "course_location": str,
                    "mon_start_time": str,
                    "mon_end_time": str,
                    // ... similar for tue/wed/thu/fri/sat/sun
                }
            },
            "prerequisites": {           // Prerequisite course information
                "text": str,            // Text description
                "required": [[int]],     // Lists of required course IDs
                "recommended": [int],    // List of recommended course IDs
                "placement": int,        // Placement course ID
                "professor_override": bool // Allow professor override
            },
            "corequisites": [int]       // IDs of corequisite courses
        }
    ]
}

Notes

  • Uses atomic transactions for database consistency

  • Course ID format: 4DDTCCC where:
    • 4: Amherst College identifier

    • DD: Department number (00-99)

    • T: Credit type (0=full, 1=half)

    • CCC: Course number

  • Logs success/failure messages

Examples

>>> python manage.py load_courses test.json

See also

amherst_coursework_algo.models

Database models used

Functions

class amherst_coursework_algo.management.commands.load_courses.Command(stdout=None, stderr=None, no_color=False, force_color=False)[source]
add_arguments(parser)[source]

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)[source]

Process JSON course data and load into database.

Parameters:
  • args (tuple) -- Variable length argument list

  • options (dict) -- Must contain 'json_file' key with path to JSON data

Return type:

None

Raises:
  • ValueError -- If course ID is invalid (not 1000000-9999999)

  • Exception -- If error occurs during database operations

Operation Flow

  1. Reads JSON file

  2. For each course:
    • Creates course ID

    • Creates/updates departments

    • Creates/updates course codes

    • Processes prerequisites

    • Creates/updates professors

    • Processes offerings

    • Creates/updates course record

    • Creates/updates enrollment caps

    • Creates/updates sections

parse_ampm_time()[source]

Parse a time string in AM/PM format into a Django time object.

Parameters:

time_str (str) -- A string representing time in 'HH:MM AM/PM' format (e.g. '9:00 AM')

Returns:

A Django time object if parsing is successful, None otherwise

Return type:

time or None

Examples

>>> parse_ampm_time('9:00 AM')
datetime.time(9, 0)
>>> parse_ampm_time('invalid')
None
>>> parse_ampm_time(None)
None