Documentation
¶
Overview ¶
Package goschedule is a library for extracting data from the UW time schedule.
Index ¶
- func ExtractClassDescriptionLinks(content, root string) []string
- func ExtractClassDescriptions(content string) (map[string]string, error)
- func Filter(in string) string
- func GenerateSchema(s interface{}) string
- func Insert(db *sql.DB, object interface{}) error
- func Select(db *sql.DB, object interface{}, conditions string) ([]interface{}, error)
- type Class
- type College
- type Dept
- type MeetingTime
- type Sect
- func (s Sect) GetGradesTokens() []map[string]bool
- func (s Sect) GetMeetingTimes() ([]MeetingTime, error)
- func (s Sect) GetOtherTokens() []map[string]bool
- func (s Sect) GetRestriction() []map[string]bool
- func (s Sect) IsFreshmen() bool
- func (s Sect) IsOpen() bool
- func (s Sect) IsQuizSection() bool
- func (s Sect) IsWithdrawal() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractClassDescriptionLinks ¶
ExtractClassDescriptionLinks grabs links from an index of links to class description pages.
func ExtractClassDescriptions ¶
ExtractClassDescriptions extracts class descriptions from content. It returns a map of class abbreviationCode's (primary key) to class descriptions.
func Filter ¶
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 ¶
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 ¶
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 ¶
ExtractClasses grabs Class structs from a string. All Class structs in the returned slice will use deptKey as their DeptKey attribute.
func (Class) DescriptionHTML ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ExtractSects grabs Sect structs from a string. All Sect structs in the returned slice will use classKey as their ClassKey attribute.
func (Sect) GetGradesTokens ¶
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 ¶
GetOtherTokens returns a map of possible other tokens to booleans depending on if they apply to this Sect.
func (Sect) GetRestriction ¶
GetRestriction returns a map of possible restriction symbols to booleans depending on if they apply to this Sect.
func (Sect) IsFreshmen ¶
IsFreshmen indicates if this Sect is restricted to freshmen by looking for key phrases/words in Sect.Info.
func (Sect) IsQuizSection ¶
IsQuizSection indicates if this Sect is a quiz section.
func (Sect) IsWithdrawal ¶
IsWithdrawal indicates if this Sect pending withdrawal by looking for key phrases/words in Sect.Info.