-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (38 loc) · 936 Bytes
/
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
package main
import (
"github.com/tschuyebuhl/scraper/cache"
"github.com/tschuyebuhl/scraper/data"
"github.com/tschuyebuhl/scraper/scraper"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
RunMetricsServer(":1337")
urls := []string{
"https://news.google.com",
}
resultsChan := make(chan data.PageData, 1000)
sem := make(chan struct{}, 20)
c := cache.NewInMemoryCache()
client := &http.Client{}
for _, url := range urls {
go func(url string) {
err := scraper.Scrape(url, c, resultsChan, 0, client, sem)
if err != nil {
slog.Error("error scraping", "error", err)
}
}(url)
}
for res := range resultsChan {
slog.Info("received results, updating metrics")
UpdateMetrics(res.URL, res.WordFrequency)
}
slog.Info("finished scraping")
// Wait for termination signal
termChan := make(chan os.Signal, 1)
signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM)
<-termChan
}