ucscclasses

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 10 Imported by: 0

README

ucscclasses

Retrieve UC Santa Cruz course information

Go Reference

Install

go get github.com/ethanent/ucscclasses

Usage

See examples in godoc.

Documentation

Index

Examples

Constants

View Source
const END_AT_TOPIC = "Course Units"

Variables

This section is empty.

Functions

func GetFixedData

func GetFixedData(c *http.Client) (terms []*Option, subjects []*Option, ges []*Option, err error)

GetFixedData returns the current terms, subjects, and GE categories.

Types

type ClassBriefInfo

type ClassBriefInfo struct {
	// AKA ClassNumber (not to be confused with number for search)
	ID string

	DetailsURL string

	// Title, eg. "CSE 13S - 01 Comp Sys and C Prog"
	FullTitle string

	// Full number, eg. "CSE 13S - 01".
	// Note that this is not to be confused with Number or ID. It just differentiates the specific class from other
	// classes of the same subject and number.
	FullNumber string

	// Name, eg. "Comp Sys and C Prog"
	Name string

	Subject    string
	Number     string
	Location   string
	TimeDay    string
	Instructor string
	Status     ClassStatus
	Enrolled   int
	Capacity   int
}

func SearchClasses

func SearchClasses(c *http.Client, opt *SearchOptions) ([]*ClassBriefInfo, error)
Example
package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/ethanent/ucscclasses"
)

var c = &http.Client{Timeout: time.Second * 5}

func main() {
	// First, get current term

	terms, _, _, err := ucscclasses.GetFixedData(c)

	if err != nil {
		panic(err)
	}

	currentTerm := terms[0].Value

	// Now, search for the class CSE 13S

	cbis, err := ucscclasses.SearchClasses(c, &ucscclasses.SearchOptions{
		Term:               currentTerm,
		Subject:            "CSE",
		Number:             "13S",
		NumberSearchMethod: ucscclasses.SearchMethodEqual,
	})

	if err != nil {
		panic(err)
	}

	// Let's iterate the CBIs to print results!

	fmt.Println(len(cbis), "results:")

	for _, cc := range cbis {
		fmt.Println("===== (" + cc.ID + ") " + cc.FullNumber + ": " + cc.Name + " =====")
		fmt.Println("This is a", cc.Subject, cc.Number, "class!")
		fmt.Println("(", cc.Enrolled, "/", cc.Capacity, ")", cc.Instructor)
		fmt.Println(cc.Location, "|", cc.TimeDay, "OPEN?", cc.Status == ucscclasses.ClassStatusOpen, cc.DetailsURL)
	}

	// You can use the DetailsURL of a CBI to retrieve class details using the Details function
}
Output:

type ClassDetails

type ClassDetails struct {
	// AKA ClassNumber (not to be confused with number for search.
	ID string

	// Title, eg. "CSE 13S - 01 Comp Sys and C Prog"
	FullTitle string

	// Full number, eg. "CSE 13S - 01".
	// Note that this is not to be confused with Number or ID. It just differentiates the specific class from other
	// classes of the same subject and number.
	FullNumber string

	// Name, eg. "Computer Systems and C Programming"
	Name string

	Subject string
	Number  string

	Status                 ClassStatus
	Capacity               int
	Enrolled               int
	WaitlistTotal          int
	WaitlistCapacity       int
	Career                 string
	Description            string
	EnrollmentRequirements string
	ClassNotes             string
	Units                  int

	// Observed types have been "Lecture" and "Seminar"
	Type string

	GE                 string
	Location           string
	TimeDay            string
	Instructor         string
	MeetingDates       string
	DiscussionSections []*DiscussionSection
}

func GetClassDetails

func GetClassDetails(c *http.Client, detailsURL string) (*ClassDetails, error)
Example
package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/ethanent/ucscclasses"
)

var c = &http.Client{Timeout: time.Second * 5}

func main() {
	// You can get a DetailsURL from a search result or elsewhere
	exampleDetailsURL := "https://pisa.ucsc.edu/class_search/index.php?action=detail&class_data=YToyOntzOjU6IjpTVFJNIjtzOjQ6IjIyMjAiO3M6MTA6IjpDTEFTU19OQlIiO3M6NToiNDQ1NzkiO30%253D"

	details, err := ucscclasses.GetClassDetails(c, exampleDetailsURL)

	if err != nil {
		panic(err)
	}

	fmt.Printf("%s %s: %s\n", details.Subject, details.Number, details.Name)
	fmt.Println(details.Instructor)
	fmt.Printf("Description: %s\n", details.Description)
	fmt.Printf("Enrollment: %d / %d\n", details.Enrolled, details.Capacity)

	fmt.Printf("Waitlist: %d / %d\n", details.WaitlistTotal, details.WaitlistCapacity)

	fmt.Println("Sections:")

	for _, ds := range details.DiscussionSections {
		fmt.Printf("  %s %s (%d / %d)\n", ds.Name, ds.Location, ds.Enrolled, ds.Capacity)
	}
}
Output:

type ClassStatus

type ClassStatus string
const (
	ClassStatusOpen           ClassStatus = "Open"
	ClassStatusClosedWaitlist ClassStatus = "Waitlist"
	ClassStatusClosed         ClassStatus = "Closed"
)

type DiscussionSection

type DiscussionSection struct {
	ID               string
	Name             string
	Status           ClassStatus
	Location         string
	Instructor       string
	Capacity         int
	Enrolled         int
	TimeDay          string
	WaitlistTotal    int
	WaitlistCapacity int
}

type Option

type Option struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type RegistrationStatus

type RegistrationStatus string
const (
	// RegistrationStatusAll includes open and closed courses
	RegistrationStatusAll RegistrationStatus = "all"

	// RegistrationStatusOpen only includes open courses
	RegistrationStatusOpen RegistrationStatus = "O"
)

type SearchMethod

type SearchMethod string
const (
	SearchMethodEqual    SearchMethod = "="
	SearchMethodContains SearchMethod = "contains"
)

type SearchOptions

type SearchOptions struct {
	// Term is required
	Term string

	// Subject is an optional selector. Use "" to ignore.
	Subject string

	// Number is an optional selector. Use "" to ignore.
	Number             string
	NumberSearchMethod SearchMethod

	// RegistrationStatus is the registrability of a course
	// Leave as nil to use RegistrationStatusAll
	RegistrationStatus *RegistrationStatus

	// GE is an optional selector. Use "" to ignore.
	GE string

	// Title (title keyword) is an optional selector. Use "" to ignore.
	Title string
}

Jump to

Keyboard shortcuts

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