-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (55 loc) · 1.42 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
59
60
package main
import (
// "fmt"
"github.com/PuerkitoBio/goquery"
"github.com/joho/godotenv"
"log"
"strings"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
var jobs []string
sites := map[string]string{"https://www.bund.net/ueber-uns/jobs": ".m-content-faq--header", "http://wwf.panda.org/jobs_wwf": ".media-heading a", "https://www.boell.de/de/jobs-der-heinrich-boell-stiftung": ".teaser__title a"}
for k, v := range sites {
jobs = append(jobs, postScrape(k, v)...)
}
// fmt.Print(jobs)
// fmt.Print(len(jobs))
mailer(jobs)
}
func postScrape(site, job string) []string {
doc, err := goquery.NewDocument(site)
if err != nil {
log.Fatal(err)
}
var hits []string
doc.Find(job).Each(func(index int, item *goquery.Selection) {
jobs := []string{"Presse", "Communications", "Forest", "Feminismus"}
title := strings.TrimSpace(item.Text())
foundJob := contains(jobs, title)
if foundJob {
// linkTag := item.Find("a")
// link, _ := linkTag.Attr("href")
// fmt.Printf("index %d\n", index)
// fmt.Printf("title %s\n", title)
// fmt.Printf("link %s\n\n", site+link)
// mailBody.WriteString(title + "\n")
hits = append(hits, title)
}
})
return hits
}
func contains(arr []string, str string) bool {
for _, a := range arr {
i := strings.Index(str, a)
if i >= 0 {
return true
} else {
// fmt.Printf("Nothing found in %s\n", str)
}
}
return false
}