Skip to content

Commit

Permalink
Changed headless mode to a flag instead of env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
justi-lai committed Oct 20, 2024
1 parent 77c54da commit 141c45c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ LOGIN_NETID=
LOGIN_PASSWORD=
LOGIN_ASTRA_USERNAME=
LOGIN_ASTRA_PASSWORD=
HEADLESS_MODE=false

#Uploader
MONGODB_URI=
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -80,6 +83,7 @@ func main() {
}

// Perform actions based on flags
utils.Headless = *headless
switch {
case *scrape:
switch {
Expand Down
2 changes: 1 addition & 1 deletion scrapers/coursebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
9 changes: 5 additions & 4 deletions utils/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ import (
"os"
"path/filepath"
"regexp"

"strconv"

Check failure on line 19 in utils/methods.go

View workflow job for this annotation

GitHub Actions / build_ubuntu

"strconv" imported and not used

Check failure on line 19 in utils/methods.go

View workflow job for this annotation

GitHub Actions / build_windows

"strconv" imported and not used
"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 {
Expand Down

0 comments on commit 141c45c

Please sign in to comment.