Documentation
¶
Overview ¶
Package utils provides shared helpers for scraping, parsing, and uploading workflows.
Index ¶
- Constants
- Variables
- func ConvertFromInterface[T string | float64](value any) *T
- func GetAllFilesWithExtension(inDir string, extension string) []string
- func GetCoursePrefixes(chromedpCtx context.Context) []string
- func GetEnv(name string) (string, error)
- func GetMapKeys[M ~map[K]V, K comparable, V any](m M) []K
- func GetMapValues[M ~map[K]V, K comparable, V any](m M) []V
- func InitChromeDp() (chromedpCtx context.Context, cancelFnc context.CancelFunc)
- func RefreshAstraToken(chromedpCtx context.Context) map[string][]string
- func RefreshToken(chromedpCtx context.Context) map[string][]string
- func Regexpf(format string, vars ...interface{}) *regexp.Regexp
- func Retry(action func() error, maxRetries int, retryCallback func(numRetries int)) error
- func TrimWhitespace(text string) string
- func VPrint(text string)
- func VPrintf(format string, vars ...any)
- func VPrintln(text string)
- func WriteJSON(filepath string, data interface{}) error
- type Logger
- type SplitWriter
Constants ¶
const Lverbose = 1 << 7
Lverbose enables verbose logging on Logger instances and global loggers.
const R_COURSE_CODE string = `[0-9vV]{4}`
R_COURSE_CODE matches a four-character course number like 2252 or V001. The first digit of a course code is the course level, the second digit is the number of credit hours.
const R_DATE_MDY string = `[A-z]+\s+[0-9]+,\s+[0-9]{4}`
R_DATE_MDY matches dates formatted like January 5, 2022.
const R_GRADE string = `[ABCFabcf][+-]?`
R_GRADE matches letter grades with optional modifiers, such as C-.
const R_SECTION_CODE string = `[0-9A-z]+`
R_SECTION_CODE matches section identifiers such as 101 or A1.
const R_SUBJECT string = `[A-Z]{2,4}`
R_SUBJECT matches a subject prefix such as HIST.
const R_SUBJ_COURSE string = `[A-Z]{2,4}\s*[0-9vV]{4}`
R_SUBJ_COURSE matches subject and course combinations without capturing groups.
const R_SUBJ_COURSE_CAP string = `([A-Z]{2,4})\s*([0-9vV]{4})`
R_SUBJ_COURSE_CAP captures both subject and course number components.
const R_TERM_CODE string = `[0-9]{2}[sufSUF]`
R_TERM_CODE matches term codes like 22S or 23f.
const R_TIME_AM_PM string = `[0-9]+:[0-9]+\s*(?:am|pm)`
R_TIME_AM_PM matches 12-hour times such as 5:22pm.
const R_WEEKDAY string = `(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day`
R_WEEKDAY matches full weekday names like Monday or Thursday.
const R_YEARS string = `(?:freshm[ae]n|sophomores?|juniors?|seniors?)`
R_YEARS matches class standing descriptors like freshmen or seniors.
Variables ¶
var Headless = true
Headless toggles whether chromedp runs without a visible browser window.
Functions ¶
func ConvertFromInterface ¶
ConvertFromInterface attempts to convert a value into the requested type and returns a pointer when successful.
func GetAllFilesWithExtension ¶
GetAllFilesWithExtension recursively gathers file paths within inDir that match extension.
func GetCoursePrefixes ¶
GetCoursePrefixes retrieves all course prefix values from CourseBook.
func GetMapKeys ¶
func GetMapKeys[M ~map[K]V, K comparable, V any](m M) []K
GetMapKeys returns a slice of all map keys.
func GetMapValues ¶
func GetMapValues[M ~map[K]V, K comparable, V any](m M) []V
GetMapValues returns a slice of all map values.
func InitChromeDp ¶
func InitChromeDp() (chromedpCtx context.Context, cancelFnc context.CancelFunc)
InitChromeDp configures and returns a chromedp context with optional headless settings.
func RefreshAstraToken ¶
RefreshAstraToken signs into Astra and returns headers containing authentication cookies.
func RefreshToken ¶
RefreshToken logs into CourseBook and returns headers containing a fresh session token.
func Regexpf ¶
Regexpf formats and compiles a regular expression pattern using fmt.Sprintf semantics.
func Retry ¶
Retry calls action until it succeeds or exceeds maxRetries, invoking retryCallback between attempts.
func TrimWhitespace ¶
TrimWhitespace removes spaces, tabs, newlines, and carriage returns from the provided string.
func VPrint ¶
func VPrint(text string)
VPrint prints text through the package-level logger when the verbose flag is set.
Types ¶
type Logger ¶
Logger extends log.Logger with helper methods that respect the verbose flag.
type SplitWriter ¶
type SplitWriter struct {
// contains filtered or unexported fields
}
SplitWriter routes writes to multiple underlying writers.
func NewSplitWriter ¶
func NewSplitWriter(writers ...io.Writer) *SplitWriter
NewSplitWriter constructs a SplitWriter that fans out writes to the provided writers.