webreg

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webreg is a client for USC Web Registration (webreg.usc.edu).

WebReg is a server-rendered application: catalog, course bin, and checkout data are parsed from its pages, while course-bin changes use its small section API. The server keeps an active term per session, so every term-scoped method selects its term before reading or changing state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinState

type BinState struct {
	Scheduled  bool `json:"scheduled"`
	Registered bool `json:"registered"`
}

BinState is a course-bin section's schedule and registration state. Checkout registers scheduled, unregistered sections and drops registered, unscheduled ones.

type CalendarEvent

type CalendarEvent struct {
	ID        string    `json:"id"`
	Title     string    `json:"title"`
	SectionID string    `json:"section_id,omitempty"`
	Status    string    `json:"status"`
	Start     time.Time `json:"start"`
	End       time.Time `json:"end"`
}

CalendarEvent is one meeting or blocked time on myCalendar. Status is Scheduled, Registered, Blocked, or Conflicted.

type Checkout

type Checkout struct {
	Term    string          `json:"term"`
	Ready   bool            `json:"ready"`
	Message string          `json:"message,omitempty"`
	Groups  []CheckoutGroup `json:"groups"`
}

Checkout is the pending registration WebReg will submit for a term: scheduled, unregistered sections to add and unscheduled, registered sections to drop, grouped as WebReg presents them.

type CheckoutGroup

type CheckoutGroup struct {
	Action  string   `json:"action"`
	Heading string   `json:"heading"`
	Courses []Course `json:"courses"`
}

CheckoutGroup is one checkout heading, e.g. Action "REGISTER", and its courses.

type CheckoutResult

type CheckoutResult struct {
	Term      string   `json:"term"`
	Succeeded bool     `json:"succeeded"`
	Status    string   `json:"status"`
	Messages  []string `json:"messages,omitempty"`
}

CheckoutResult is WebReg's registration response. WebReg does not process partial registrations: on failure nothing was changed.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client reads and changes WebReg state with an authenticated session. A client is sequential: WebReg's active term is shared session state.

func New

func New(httpClient Doer) *Client

New creates a WebReg client from an authenticated HTTP client.

func Open

func Open(ctx context.Context, options auth.Options) (*Client, error)

Open signs in through USC SSO and returns an authenticated client. See auth.Options for supplying credentials and keeping the session between runs. It never prompts; authentication failures are *auth.SiteError values.

func (*Client) Add

func (c *Client) Add(ctx context.Context, term string, sectionID int) error

Add places a section in the course bin. It does not register; schedule the section and submit checkout to register.

func (*Client) Calendar

func (c *Client) Calendar(ctx context.Context, term string) ([]CalendarEvent, error)

Calendar returns a term's weekly calendar of scheduled, registered, and conflicting meetings. Dates are a representative week, not term dates.

func (*Client) Checkout

func (c *Client) Checkout(ctx context.Context, term string) (*Checkout, error)

Checkout previews the changes Submit would send. It changes nothing.

func (*Client) CourseBin

func (c *Client) CourseBin(ctx context.Context, term string) (*CourseBin, error)

CourseBin reads a term's course bin.

func (*Client) Courses

func (c *Client) Courses(ctx context.Context, term string, query CourseQuery) ([]Course, error)

Courses lists a term's courses for a program or a single course code, following WebReg's pagination. Each section reports whether it is already in the course bin.

func (*Client) Programs

func (c *Client) Programs(ctx context.Context, term string) ([]School, error)

Programs lists a term's schools and their programs.

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, term string, sectionID int) error

Remove deletes an unscheduled, unregistered section from the course bin.

func (*Client) Schedule

func (c *Client) Schedule(ctx context.Context, term string, sectionID int) error

Schedule marks a course-bin section to be registered at checkout, or keeps a registered section from being dropped.

func (*Client) SelectTerm

func (c *Client) SelectTerm(ctx context.Context, term string) error

SelectTerm makes term WebReg's active term for this session.

func (*Client) SetGradeOption

func (c *Client) SetGradeOption(ctx context.Context, term string, sectionID int, code string) (string, error)

SetGradeOption changes a course-bin section's grade option to code, one of the section's GradeOption.Choices (for example L, PN, or V). Unregistered sections change immediately; registered sections submit a change request that takes effect when checkout is submitted. It returns WebReg's response, such as "Updated-PN".

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, term string) (*CheckoutResult, error)

Submit registers and drops the sections Checkout lists. This is the same irreversible action as WebReg's Submit button. Callers should show the preview from Checkout and obtain the student's confirmation first.

func (*Client) Terms

func (c *Client) Terms(ctx context.Context) ([]Term, error)

Terms lists the terms open in WebReg. Active marks the session's current term, if one has been selected.

func (*Client) Unschedule

func (c *Client) Unschedule(ctx context.Context, term string, sectionID int) error

Unschedule removes a section from the planned schedule. A registered section that is unscheduled is dropped when checkout is submitted.

type Course

type Course struct {
	Code          string    `json:"code"`
	Title         string    `json:"title"`
	Description   string    `json:"description,omitempty"`
	Prerequisites []string  `json:"prerequisites,omitempty"`
	Sections      []Section `json:"sections"`
}

Course is a WebReg course and the sections shown for it on one page.

type CourseBin

type CourseBin struct {
	Term               string   `json:"term"`
	RegisteredSections int      `json:"registered_sections"`
	ScheduledSections  int      `json:"scheduled_sections"`
	AsOf               string   `json:"as_of,omitempty"`
	Courses            []Course `json:"courses"`
}

CourseBin is a term's myCourseBin: courses the student is planning or registered in, each section with its schedule/registration state.

func (*CourseBin) Section

func (b *CourseBin) Section(id int) (*Section, error)

Section returns the course-bin section with id, or an error if it is not in the bin.

type CourseQuery

type CourseQuery struct {
	Program string // subject code, e.g. BUAD
	Course  string // course code, e.g. BUAD-302
}

CourseQuery selects WebReg catalog courses. Set exactly one field.

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is the HTTP surface the client needs. auth.Session satisfies it.

type Error

type Error struct {
	Operation string
	Status    int
	Message   string
}

Error describes a WebReg request the server rejected. Message is a short server explanation when one was safe to include.

func (*Error) Error

func (e *Error) Error() string

type GradeChoice

type GradeChoice struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

GradeChoice is a grade-option code such as L (letter) and its label.

type GradeOption

type GradeOption struct {
	Current       string        `json:"current,omitempty"`
	Choices       []GradeChoice `json:"choices,omitempty"`
	ChangeRequest bool          `json:"change_request"`
	// contains filtered or unexported fields
}

GradeOption is a course-bin section's grading basis and the choices WebReg offers. ChangeRequest is true for registered sections, whose change is submitted as a request instead of applied directly.

type Program

type Program struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

Program is a subject such as BUAD that can be passed to Courses.

type School

type School struct {
	Name     string    `json:"name"`
	Programs []Program `json:"programs"`
}

School groups the programs (subject codes) WebReg lists under a school.

type Seats

type Seats struct {
	Registered int    `json:"registered"`
	Capacity   int    `json:"capacity"`
	Closed     bool   `json:"closed"`
	Text       string `json:"text"`
}

Seats is the section's registration count as WebReg displays it.

type Section

type Section struct {
	ID int `json:"id"`
	// Clearance is WebReg's letter beside the section ID: "R" sections are
	// open to registration and "D" sections need department clearance.
	Clearance   string       `json:"clearance,omitempty"`
	Session     string       `json:"session,omitempty"`
	Type        string       `json:"type,omitempty"`
	Units       string       `json:"units,omitempty"`
	Seats       Seats        `json:"seats"`
	Times       []string     `json:"times,omitempty"`
	Days        []string     `json:"days,omitempty"`
	Instructors []string     `json:"instructors,omitempty"`
	Locations   []string     `json:"locations,omitempty"`
	Notes       []string     `json:"notes,omitempty"`
	InCourseBin *bool        `json:"in_course_bin,omitempty"`
	CourseBin   *BinState    `json:"course_bin,omitempty"`
	GradeOption *GradeOption `json:"grade_option,omitempty"`
}

Section is one WebReg section row. Fields that only one page shows are omitted elsewhere: InCourseBin comes from catalog pages, CourseBin and GradeOption from the course bin.

type Term

type Term struct {
	Code   string `json:"code"`
	Name   string `json:"name"`
	Active bool   `json:"active"`
}

Term is a registration term WebReg offers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL