From 8616d615551f0c5c2a32253541bdc802bf110a13 Mon Sep 17 00:00:00 2001 From: vin Date: Wed, 17 Jan 2024 16:51:00 -0500 Subject: [PATCH] exit if the CANVAS environment variables are not set --- aplus.go | 4 ++-- canvas.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/aplus.go b/aplus.go index a84df8c..1b491a7 100644 --- a/aplus.go +++ b/aplus.go @@ -8,8 +8,8 @@ import ( "net/http" "net/url" "regexp" - "strings" "strconv" + "strings" "time" ) @@ -238,7 +238,7 @@ func timetable(course_code int) { hour, _ := strconv.Atoi(jsdate[3]) min, _ := strconv.Atoi(jsdate[4]) sec, _ := strconv.Atoi(jsdate[5]) - date := time.Date(year, time.Month(month + 1), day, hour, min, sec, 0, time.UTC).Local() + date := time.Date(year, time.Month(month+1), day, hour, min, sec, 0, time.UTC).Local() fmt.Println(date.Format("Mon Jan 02 15:04:05 MST 2006") + ": " + strings.Replace(statuses[i], "title=\"\">", "", 1)) } diff --git a/canvas.go b/canvas.go index f1a2375..41afce7 100644 --- a/canvas.go +++ b/canvas.go @@ -15,8 +15,18 @@ import ( func initialize() { instance_url := os.Getenv("CANVAS_INSTANCE") + if len(instance_url) == 0 { + fmt.Println("The CANVAS_INSTANCE environment variable seems to be empty. Exiting.") + os.Exit(1) + } + base_link = instance_url + "/api/v1" token = os.Getenv("CANVAS_API_KEY") + if len(token) == 0 { + fmt.Println("The CANVAS_API_KEY environment variable seems to be empty. Exiting.") + os.Exit(1) + } + jar, _ := cookiejar.New(&cookiejar.Options{ PublicSuffixList: publicsuffix.List, })