Skip to content

Commit 42856b7

Browse files
authored
Changed headless mode to a flag instead of env variable (#37)
* Changed headless mode to a flag instead of env variable * Removed strconv from utils.methods
1 parent 77c54da commit 42856b7

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

.env.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ LOGIN_NETID=
33
LOGIN_PASSWORD=
44
LOGIN_ASTRA_USERNAME=
55
LOGIN_ASTRA_PASSWORD=
6-
HEADLESS_MODE=false
76

87
#Uploader
98
MONGODB_URI=

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func main() {
5151
// Flags for logging
5252
verbose := flag.Bool("verbose", false, "Enables verbose logging, good for debugging purposes.")
5353

54+
// Flag for headless mode
55+
headless := flag.Bool("headless", true, "Enables headless mode for chromedp. Defaults to true.")
56+
5457
// Parse flags
5558
flag.Parse()
5659

@@ -80,6 +83,7 @@ func main() {
8083
}
8184

8285
// Perform actions based on flags
86+
utils.Headless = *headless
8387
switch {
8488
case *scrape:
8589
switch {

scrapers/coursebook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
func ScrapeCoursebook(term string, startPrefix string, outDir string) {
2121

2222
// Load env vars
23-
if err := godotenv.Load(); err != nil {
23+
if err := godotenv.Load(".env.template"); err != nil {
2424
log.Panic("Error loading .env file")
2525
}
2626

utils/methods.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ import (
1515
"os"
1616
"path/filepath"
1717
"regexp"
18-
"strconv"
18+
1919
"strings"
2020

21-
"github.com/chromedp/cdproto/network"
2221
"github.com/chromedp/cdproto/cdp"
22+
"github.com/chromedp/cdproto/network"
2323
"github.com/chromedp/chromedp"
2424
)
2525

26+
var Headless = true
27+
2628
// Initializes Chrome DevTools Protocol
2729
func InitChromeDp() (chromedpCtx context.Context, cancelFnc context.CancelFunc) {
2830
log.Printf("Initializing chromedp...")
29-
headlessEnv, present := os.LookupEnv("HEADLESS_MODE")
30-
doHeadless, _ := strconv.ParseBool(headlessEnv)
31-
if present && doHeadless {
31+
if Headless {
3232
chromedpCtx, cancelFnc = chromedp.NewContext(context.Background())
3333
log.Printf("Initialized chromedp!")
3434
} else {

0 commit comments

Comments
 (0)