-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e763b40
commit b6aa71e
Showing
9 changed files
with
636 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Penn OpenData API | ||
[](https://pkg.go.dev/github.com/penn-automate/penn-opendata-api) | ||
|
||
This package provides an easy-to-use Go Binding for accessing University of Pennsylvania's OpenData API. | ||
|
||
This API is implemented following the specifications in this [documentation](https://esb.isc-seo.upenn.edu/8091/documentation). | ||
This API is implemented following the specifications in this [documentation](https://app.swaggerhub.com/apis-docs/UPennISC/open-data/prod). | ||
|
||
This package is licensed under [Unlicense](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package opendata | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Course is a normalized struct for course and section ID. | ||
type Course struct{ string } | ||
|
||
func validCourse(course string) bool { | ||
if len(course) <= 0 { | ||
return false | ||
} | ||
switch course[len(course)-1] { | ||
case 'A', 'B', 'a', 'b': | ||
course = course[:len(course)-1] | ||
} | ||
num, err := strconv.Atoi(course) | ||
if err != nil || num <= 0 { | ||
return false | ||
} | ||
return num <= 9999 | ||
} | ||
|
||
// NewCourse generates a new Course instance based on course subject, number, and section ID. | ||
func NewCourse(subject, number, section string) *Course { | ||
subject = strings.ToUpper(strings.TrimSpace(subject)) | ||
section = strings.ToUpper(strings.TrimSpace(section)) | ||
if len(subject) > 4 || len(subject) <= 1 || !validCourse(number) || len(section) != 3 { | ||
return nil | ||
} | ||
return &Course{fmt.Sprintf("%s%04s%s", subject, number, section)} | ||
} | ||
|
||
var courseRegex = regexp.MustCompile(`^([a-zA-Z]{2,4})\s*-?([0-9]{2,4}[AB]?)-?([0-9a-zA-Z]{3})$`) | ||
|
||
// ParseCourse generates a new Course instance based on course ID string using regex to match. | ||
// ParseCourse("MUSC0050003") | ||
func ParseCourse(course string) *Course { | ||
match := courseRegex.FindStringSubmatch(course) | ||
if len(match) != 4 { | ||
return nil | ||
} | ||
return NewCourse(match[1], match[2], match[3]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/penn-automate/penn-opendata-api | ||
|
||
go 1.13 | ||
|
||
require golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.