Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed headless mode to a flag instead of env variable #37

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually an error here I noticed after-the-fact (which I've fixed via da5bab6); this shouldn't be changed to read from .env.template since the template file is only used as a basis for creating an actual .env file (which is what this loads from by default)

log.Panic("Error loading .env file")
}

Expand Down
10 changes: 5 additions & 5 deletions utils/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ 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)
jpahm marked this conversation as resolved.
Show resolved Hide resolved
if present && doHeadless {
if Headless {
chromedpCtx, cancelFnc = chromedp.NewContext(context.Background())
log.Printf("Initialized chromedp!")
} else {
Expand Down
Loading