diff --git a/.env.template b/.env.template index a560670..8b1cd0e 100644 --- a/.env.template +++ b/.env.template @@ -3,7 +3,6 @@ LOGIN_NETID= LOGIN_PASSWORD= LOGIN_ASTRA_USERNAME= LOGIN_ASTRA_PASSWORD= -HEADLESS_MODE=false #Uploader MONGODB_URI= \ No newline at end of file diff --git a/main.go b/main.go index ff46c56..2d2797e 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,9 @@ func main() { // Flags for logging verbose := flag.Bool("verbose", false, "Enables verbose logging, good for debugging purposes.") + // Flag for headless mode + headless := flag.Bool("headless", true, "Enables headless mode for chromedp. Defaults to true.") + // Parse flags flag.Parse() @@ -80,6 +83,7 @@ func main() { } // Perform actions based on flags + utils.Headless = *headless switch { case *scrape: switch { diff --git a/scrapers/coursebook.go b/scrapers/coursebook.go index e9e1f91..87ca95c 100644 --- a/scrapers/coursebook.go +++ b/scrapers/coursebook.go @@ -20,7 +20,7 @@ import ( func ScrapeCoursebook(term string, startPrefix string, outDir string) { // Load env vars - if err := godotenv.Load(); err != nil { + if err := godotenv.Load(".env.template"); err != nil { log.Panic("Error loading .env file") } diff --git a/utils/methods.go b/utils/methods.go index da9193c..bdff379 100644 --- a/utils/methods.go +++ b/utils/methods.go @@ -15,20 +15,21 @@ import ( "os" "path/filepath" "regexp" + "strconv" "strings" - "github.com/chromedp/cdproto/network" "github.com/chromedp/cdproto/cdp" + "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" ) +var Headless = true + // Initializes Chrome DevTools Protocol func InitChromeDp() (chromedpCtx context.Context, cancelFnc context.CancelFunc) { log.Printf("Initializing chromedp...") - headlessEnv, present := os.LookupEnv("HEADLESS_MODE") - doHeadless, _ := strconv.ParseBool(headlessEnv) - if present && doHeadless { + if Headless { chromedpCtx, cancelFnc = chromedp.NewContext(context.Background()) log.Printf("Initialized chromedp!") } else {