goschedule

package
v0.0.0-...-30f2fe3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package goschedule is a library for extracting data from the UW time schedule.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractClassDescriptionLinks(content, root string) []string

ExtractClassDescriptionLinks grabs links from an index of links to class description pages.

func ExtractClassDescriptions

func ExtractClassDescriptions(content string) (map[string]string, error)

ExtractClassDescriptions extracts class descriptions from content. It returns a map of class abbreviationCode's (primary key) to class descriptions.

func Filter

func Filter(in string) string

Filter returns a copy of the input string with UTF-8 invalid characters replaced with `?` and unescapes HTML escape sequences.

func GenerateSchema

func GenerateSchema(s interface{}) string

func Insert

func Insert(db *sql.DB, object interface{}) error

Insert inserts a struct into the database. It ignores struct fields with the tag `ignore:"true"`. It returns records from a SQL query in the form:

'INSERT INTO <lowercase struct name> VALUES (<non-ignored struct field values, in sequential order)'

For example, the following:

type Banana struct {
	Color     string
	Length    int
	index     int
	Throwable bool `ignore:"true"`
}

Insert(db, Banana{"yellow", 12, 0, true})

will run the query:

INSERT INTO banana VALUES ('yellow', 12, true);

Note that unexported fields are still added to the query unless they have the ignore tag.

func Select

func Select(db *sql.DB, object interface{}, conditions string) ([]interface{}, error)

Select uses an empty struct to query the database and return a slice of the corresponding structs. It returns records from a SQL query in the form:

'SELECT * FROM <lowercase struct name> [additional SQL clauses]...'

Additional SQL clauses can be specified in the filters parameter. For example `select(db, Sect{}, "ORDER BY sln LIMIT 5")` runs the query:

SELECT * FROM sect ORDER BY sln LIMIT 5;

Types

type Class

type Class struct {
	DeptKey          string `fk:"Dept"`
	AbbreviationCode string `pk:"true"`
	Abbreviation     string
	Code             string
	Name             string
	Description      string
	// contains filtered or unexported fields
}

A Class is UW class that has many sections.

func ExtractClasses

func ExtractClasses(content, deptKey string) []Class

ExtractClasses grabs Class structs from a string. All Class structs in the returned slice will use deptKey as their DeptKey attribute.

func (Class) DescriptionHTML

func (c Class) DescriptionHTML() template.HTML

DescriptionHTML outputs non-escaped HTML of a Class.Description for use in a template.

type College

type College struct {
	Name         string
	Abbreviation string `pk:"true"`
	// contains filtered or unexported fields
}

A College is a UW college that has many departments

func ExtractColleges

func ExtractColleges(content string) ([]College, error)

ExtractColleges grabs College structs from a string

type Dept

type Dept struct {
	CollegeKey   string `fk:"College"`
	Name         string
	Abbreviation string `pk:"true"`
	Link         string
}

A Department is a UW department that has many classes.

func ExtractDepts

func ExtractDepts(content, collegeKey, url string, processed *map[string]int) ([]Dept, error)

Extract grabs Dept structs from a string.

All Dept structs in the returned slice will use collegeKey as their collegeKey attribute. processed is a map of Dept.Abbreviation's that have already been processed. The int values are not used. ExtractDepts will skip a Dept if its abbreviation is in processed. Else, it will add the abbreviation to processed.

Note that the department's abbreviation (primary key) cannot be scraped from the department index. The abbreviation from the class listing by visiting the department page. Use Dept.ScrapeAbbreviation with a class index page (Dept.Link).

func (*Dept) ScrapeAbbreviation

func (d *Dept) ScrapeAbbreviation(content string) error

ExtractAbbreviation extracts a department abbreviation from content (assumed to be a class index of a department) and sets the Dept.Abbreviation attribute.

Returns an error if no department abbreviation was found.

type MeetingTime

type MeetingTime struct {
	Days     string
	Time     string
	Building string
	Room     string
}

A MeetingTime represents when a Sect is held. Some Sect's have multiple meeting times.

func (MeetingTime) MapDays

func (m MeetingTime) MapDays() map[string]bool

MapDays returns a map of possible days to booleans depending on what days this Section is held.

type Sect

type Sect struct {
	ClassKey     string `fk:"Class"`
	Restriction  string
	SLN          string `pk:"true"`
	Section      string
	Credit       string
	MeetingTimes string // JSON representation
	Instructor   string
	Status       string
	TakenSpots   int64
	TotalSpots   int64
	Grades       string
	Fee          string
	Other        string
	Info         string
}

A Sect is a UW section.

func ExtractSects

func ExtractSects(content, classKey string) ([]Sect, error)

ExtractSects grabs Sect structs from a string. All Sect structs in the returned slice will use classKey as their ClassKey attribute.

func (Sect) GetGradesTokens

func (s Sect) GetGradesTokens() []map[string]bool

GetGradesTokens returns a map of possible grade tokens to booleans depending on if they apply to this Sect.

func (Sect) GetMeetingTimes

func (s Sect) GetMeetingTimes() ([]MeetingTime, error)

GetMeetingTimes parses the JSON representation of meeting times from the Section. Returns a slice of MeetingTime structs, or an empty slice if the section has no MeetingTime's.

func (Sect) GetOtherTokens

func (s Sect) GetOtherTokens() []map[string]bool

GetOtherTokens returns a map of possible other tokens to booleans depending on if they apply to this Sect.

func (Sect) GetRestriction

func (s Sect) GetRestriction() []map[string]bool

GetRestriction returns a map of possible restriction symbols to booleans depending on if they apply to this Sect.

func (Sect) IsFreshmen

func (s Sect) IsFreshmen() bool

IsFreshmen indicates if this Sect is restricted to freshmen by looking for key phrases/words in Sect.Info.

func (Sect) IsOpen

func (s Sect) IsOpen() bool

IsOpen indicates if this Sect has open spots.

func (Sect) IsQuizSection

func (s Sect) IsQuizSection() bool

IsQuizSection indicates if this Sect is a quiz section.

func (Sect) IsWithdrawal

func (s Sect) IsWithdrawal() bool

IsWithdrawal indicates if this Sect pending withdrawal by looking for key phrases/words in Sect.Info.

Jump to

Keyboard shortcuts

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