-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (46 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"fmt"
"os"
"github.com/jmbarne3/web-crawler/crawler"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
var domain_path string
var analytics_path string
var output_path string
api_key := flag.String("api-key", os.Getenv("OPEN_AI_API_KEY"), "The API key to use to connect to the Open AI API.")
flag.Parse()
for idx, val := range flag.Args() {
switch idx {
case 0:
domain_path = val
case 1:
analytics_path = val
case 2:
output_path = val
}
}
if (domain_path == "") || (analytics_path == "") || (output_path == "") {
fmt.Println(usage())
os.Exit(1)
}
if *api_key == "" {
fmt.Println("An API Key is required. Please add it to your .env file or provide is as an argument.")
fmt.Println(usage())
os.Exit(1)
}
config := crawler.CrawlerConfig{
DomainFilePath: domain_path,
AnalyticsFilePath: analytics_path,
OutputFilePath: output_path,
APIKey: *api_key,
}
crawler.Crawl(&config)
}
func usage() string {
s := "go-web-crawler [domain-file-path] [analytics-file-path] [output-file-path] [--api-key=<api-key>]"
return s
}