Skip to content

Commit

Permalink
Merge pull request #24 from austin1237/scraper-keyword
Browse files Browse the repository at this point in the history
scraper now passes matched keyword to the job api
  • Loading branch information
austin1237 authored Apr 30, 2024
2 parents 4d97240 + 10a057e commit e48f488
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
12 changes: 7 additions & 5 deletions scraper/interest/interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
"sync"
)

func CheckIfInterested(description string) bool {
keywords := []string{"typescript", "node", "nodejs", "node.js", "go", "golang"}
func CheckIfInterested(description string) string {
keywords := []string{"go", "golang", "node", "nodejs", "node.js", "typescript"}
// Check if keywords are present in the job's text
descriptionToLower := strings.ToLower(description)
for _, keyword := range keywords {
pattern := "\\b" + keyword + "\\b"
match, _ := regexp.MatchString(pattern, descriptionToLower)
if match {
return true
return keyword
}
}
return false
return ""
}

type JobInfoGetter func(string, string) (string, error)
Expand All @@ -43,7 +43,9 @@ func FilterInterest(proxyUrl string, possibleJobs []job.Job, jobInfoGetter JobIn
if err != nil {
fmt.Println(err)
}
if CheckIfInterested(description) {

possibleJob.Keyword = CheckIfInterested(description)
if possibleJob.Keyword != "" {
interestingJobs = append(interestingJobs, possibleJob)
}
goroutineCount--
Expand Down
14 changes: 7 additions & 7 deletions scraper/interest/interest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ func TestCheckIfInterested(t *testing.T) {
tests := []struct {
name string
description string
want bool
want string
}{
{
name: "contains typescript",
description: "This is a job for a TypeScript developer",
want: true,
want: "typescript",
},
{
name: "contains node",
description: "This is a job for a Node.js developer",
want: true,
want: "node",
},
{
name: "contains go",
description: "This is a job for a Go developer",
want: true,
want: "go",
},
{
name: "contains go",
description: "This is a job for go.",
want: true,
want: "go",
},
{
name: "contains django",
description: "This is a job for a django developer in Chicago",
want: false,
want: "",
},
{
name: "does not contain keyword",
description: "This is a job for a Python developer",
want: false,
want: "",
},
}

Expand Down
1 change: 1 addition & 0 deletions scraper/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Job struct {
Title string
Company string
Link string
Keyword string
}

type Response struct {
Expand Down
4 changes: 3 additions & 1 deletion scraper/remotive/remotive.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ func ScanNewJobs(baseURL string, proxyUrl string) []job.Job {
log.Println("Remotive total jobs found", len(remotiveJobs))
var interestingJobs []job.Job
for _, newJob := range remotiveJobs {
if interest.CheckIfInterested(newJob.Description) {
keyword := interest.CheckIfInterested(newJob.Description)
if keyword != "" {
interestingJobs = append(interestingJobs, job.Job{
Title: newJob.Title,
Link: newJob.URL,
Company: newJob.CompanyName,
Keyword: keyword,
})
}
}
Expand Down

0 comments on commit e48f488

Please sign in to comment.