-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdbdc64
commit 51737d6
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package remotive | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"net/http" | ||
"scraper/interest" | ||
"scraper/job" | ||
"time" | ||
) | ||
|
||
type remotiveJob struct { | ||
ID int `json:"id"` | ||
URL string `json:"url"` | ||
Title string `json:"title"` | ||
CompanyName string `json:"company_name"` | ||
CompanyLogo string `json:"company_logo"` | ||
Category string `json:"category"` | ||
JobType string `json:"job_type"` | ||
PublicationDate string `json:"publication_date"` | ||
CandidateRequiredLocation string `json:"candidate_required_location"` | ||
Salary string `json:"salary"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type JobsResponse struct { | ||
JobCount int `json:"job-count"` | ||
Jobs []remotiveJob `json:"jobs"` | ||
} | ||
|
||
func callApi(site string) []remotiveJob { | ||
newJobs := []remotiveJob{} | ||
resp, err := http.Get(site) | ||
|
||
if err != nil { | ||
log.Println("error calling remotive api", err) | ||
return newJobs | ||
} | ||
defer resp.Body.Close() | ||
var jobsResponse JobsResponse | ||
err = json.NewDecoder(resp.Body).Decode(&jobsResponse) | ||
|
||
if err != nil { | ||
log.Println("error decoding response", err) | ||
return newJobs | ||
} | ||
yesterday := time.Now().Add(-24 * time.Hour) | ||
|
||
for _, newJob := range jobsResponse.Jobs { | ||
recent := false | ||
locationMatch := false | ||
pubDate, err := time.Parse("2006-01-02T15:04:05", newJob.PublicationDate) | ||
if err != nil { | ||
log.Println("error parsing date", err) | ||
continue | ||
} | ||
|
||
if pubDate.After(yesterday) { | ||
recent = true | ||
} | ||
|
||
if newJob.CandidateRequiredLocation == "USA" || newJob.CandidateRequiredLocation == "Worldwide" || newJob.CandidateRequiredLocation == "" { | ||
locationMatch = true | ||
} | ||
|
||
if recent && locationMatch { | ||
newJobs = append(newJobs, newJob) | ||
} | ||
|
||
} | ||
return newJobs | ||
} | ||
|
||
func ScanNewJobs(siteEBaseUrl string, proxyUrl string) []job.Job { | ||
jobs := callApi(siteEBaseUrl + "/api/remote-jobs?category=software-dev&limit=100") | ||
log.Println("Remotive total jobs found", len(jobs)) | ||
var interestingJobs []job.Job | ||
|
||
for _, newJob := range jobs { | ||
if interest.CheckIfInterested(newJob.Description) { | ||
interestingJobs = append(interestingJobs, job.Job{ | ||
Title: newJob.Title, | ||
Link: newJob.URL, | ||
Company: newJob.CompanyName, | ||
}) | ||
} | ||
} | ||
log.Println("Remotive interesting jobs", len(interestingJobs)) | ||
return interestingJobs | ||
} |