From c20690f3238a4009ca5138b61c435f6a7b0d71ba Mon Sep 17 00:00:00 2001 From: christian Date: Sat, 8 Jun 2024 16:48:00 +0200 Subject: [PATCH] added aws lambda integrations --- go.mod | 1 + go.sum | 2 ++ scraper.go | 27 ++++++++------------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 5f50063..1c67557 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/antchfx/htmlquery v1.3.1 // indirect github.com/antchfx/xmlquery v1.4.0 // indirect github.com/antchfx/xpath v1.3.0 // indirect + github.com/aws/aws-lambda-go v1.47.0 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gocolly/colly v1.2.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect diff --git a/go.sum b/go.sum index cf66d2f..874c4c8 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/antchfx/xmlquery v1.4.0 h1:xg2HkfcRK2TeTbdb0m1jxCYnvsPaGY/oeZWTGqX/0h github.com/antchfx/xmlquery v1.4.0/go.mod h1:Ax2aeaeDjfIw3CwXKDQ0GkwZ6QlxoChlIBP+mGnDFjI= github.com/antchfx/xpath v1.3.0 h1:nTMlzGAK3IJ0bPpME2urTuFL76o4A96iYvoKFHRXJgc= github.com/antchfx/xpath v1.3.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= +github.com/aws/aws-lambda-go v1.47.0 h1:0H8s0vumYx/YKs4sE7YM0ktwL2eWse+kfopsRI1sXVI= +github.com/aws/aws-lambda-go v1.47.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= diff --git a/scraper.go b/scraper.go index 00a6023..f64bf31 100644 --- a/scraper.go +++ b/scraper.go @@ -1,12 +1,11 @@ package main import ( - "encoding/json" + "context" "fmt" - "log" - "os" "strings" + "github.com/aws/aws-lambda-go/lambda" "github.com/gocolly/colly" ) @@ -44,14 +43,8 @@ func skillChecker(description string) skills { // Slice to store job details var jobs []job -func main() { +func handler(ctx context.Context) ([]job, error) { - fName := "jobs.json" - file, err := os.Create(fName) - if err != nil { - log.Fatalf("Cannot create file %q: %s", fName, err) - } - defer file.Close() baseUrl := "https://thehub.io" searchString := "https://thehub.io/jobs?roles=frontenddeveloper&roles=fullstackdeveloper&roles=backenddeveloper&roles=devops&paid=true&countryCode=DK&sorting=newJobs" // Instantiate default collector @@ -118,13 +111,9 @@ func main() { }) c.Visit(searchString) - - // Encode jobs slice to JSON - encoder := json.NewEncoder(file) - encoder.SetIndent("", " ") // Pretty-print with indentation - if err := encoder.Encode(jobs); err != nil { - log.Fatalf("Cannot write to file %q: %s", fName, err) - } - - fmt.Println("Job details successfully written to", fName) + return jobs, nil +} + +func main() { + lambda.Start(handler) }