feat: job hunt bot and feed scanner
This commit is contained in:
+307
@@ -0,0 +1,307 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Source is one company's public job board feed. These are the feeds the
|
||||
// applicant tracking systems publish for exactly this purpose: no key, no
|
||||
// login, no scraping.
|
||||
type Source struct {
|
||||
Company string
|
||||
ATS string // greenhouse, lever, ashby, recruitee, smartrecruiters
|
||||
Slug string
|
||||
}
|
||||
|
||||
// sources is the watch list. To add a company, find which ATS its careers
|
||||
// page uses and its board name there, then check with `jobhunt scan --dry-run`.
|
||||
// Booking.com has no public feed: send its links to the bot by hand.
|
||||
var sources = []Source{
|
||||
{"Adyen", "greenhouse", "adyen"},
|
||||
{"bol", "greenhouse", "bolcom"},
|
||||
{"bunq", "recruitee", "bunq"},
|
||||
{"Bynder", "ashby", "bynder"},
|
||||
{"Catawiki", "greenhouse", "catawiki"},
|
||||
{"Channable", "recruitee", "channable"},
|
||||
{"Coolblue", "smartrecruiters", "coolblue"},
|
||||
{"Crisp", "ashby", "crisp"},
|
||||
{"Databricks", "greenhouse", "databricks"},
|
||||
{"Datadog", "greenhouse", "datadog"},
|
||||
{"DataSnipper", "ashby", "datasnipper"},
|
||||
{"Flow Traders", "greenhouse", "flowtraders"},
|
||||
{"GitLab", "greenhouse", "gitlab"},
|
||||
{"IMC Trading", "greenhouse", "imc"},
|
||||
{"Mendix", "lever", "mendix"},
|
||||
{"Mollie", "ashby", "mollie"},
|
||||
{"Optiver", "greenhouse", "optiverus"},
|
||||
{"Picnic", "smartrecruiters", "picnic"},
|
||||
{"Solvinity", "recruitee", "solvinity"},
|
||||
}
|
||||
|
||||
// Job is one listing from a feed. Text is filled from the feed when the feed
|
||||
// carries the description; otherwise DetailURL points at a JSON document that
|
||||
// does (fetched only for jobs that pass the filter).
|
||||
type Job struct {
|
||||
Key string // stable across runs: ats:slug:id
|
||||
Company string
|
||||
Title string
|
||||
Location string
|
||||
URL string
|
||||
Text string
|
||||
DetailURL string
|
||||
}
|
||||
|
||||
var (
|
||||
// The search profile: backend and fullstack roles in the Netherlands.
|
||||
reWantTitle = regexp.MustCompile(`(?i)back[- ]?end|full[- ]?stack|software (engineer|developer|ontwikkelaar)|python|golang|django|\bgo (engineer|developer)`)
|
||||
reSkipTitle = regexp.MustCompile(`(?i)\b(intern|internship|stage|stagiair|werkstudent|graduate|manager|director|head of|vp|principal|staff|mobile|ios|android|embedded|firmware|fpga|hardware|qa|sdet|test|sales|solutions?|support|recruiter)\b`)
|
||||
reFrontOnly = regexp.MustCompile(`(?i)front[- ]?end`)
|
||||
reNL = regexp.MustCompile(`(?i)netherlands|nederland|amsterdam|utrecht|rotterdam|eindhoven|den haag|the hague|delft|leiden|zwolle|groningen|hoofddorp|arnhem|nijmegen|den bosch|amersfoort|haarlem|\bNL\b`)
|
||||
)
|
||||
|
||||
// wanted is the cheap filter that runs before Claude sees anything.
|
||||
func wanted(j Job) bool {
|
||||
if !reNL.MatchString(j.Location) || !reWantTitle.MatchString(j.Title) || reSkipTitle.MatchString(j.Title) {
|
||||
return false
|
||||
}
|
||||
// "Frontend engineer" is out, "Fullstack (frontend-leaning)" stays in.
|
||||
return !reFrontOnly.MatchString(j.Title) || regexp.MustCompile(`(?i)full[- ]?stack|back[- ]?end`).MatchString(j.Title)
|
||||
}
|
||||
|
||||
func feedURL(s Source) (string, error) {
|
||||
switch s.ATS {
|
||||
case "greenhouse":
|
||||
return "https://boards-api.greenhouse.io/v1/boards/" + s.Slug + "/jobs?content=true", nil
|
||||
case "lever":
|
||||
return "https://api.lever.co/v0/postings/" + s.Slug + "?mode=json", nil
|
||||
case "ashby":
|
||||
return "https://api.ashbyhq.com/posting-api/job-board/" + s.Slug, nil
|
||||
case "recruitee":
|
||||
return "https://" + s.Slug + ".recruitee.com/api/offers/", nil
|
||||
case "smartrecruiters":
|
||||
return "https://api.smartrecruiters.com/v1/companies/" + s.Slug + "/postings?limit=100", nil
|
||||
}
|
||||
return "", fmt.Errorf("unknown ATS %q", s.ATS)
|
||||
}
|
||||
|
||||
// anyID turns a JSON id (number or string) into its text form.
|
||||
func anyID(raw json.RawMessage) string {
|
||||
var s string
|
||||
if json.Unmarshal(raw, &s) == nil {
|
||||
return s
|
||||
}
|
||||
var n json.Number
|
||||
if json.Unmarshal(raw, &n) == nil {
|
||||
return n.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func joinText(parts ...string) string {
|
||||
var out []string
|
||||
for _, p := range parts {
|
||||
if p = strings.TrimSpace(p); p != "" {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
return strings.Join(out, "\n\n")
|
||||
}
|
||||
|
||||
// parseFeed turns one feed document into jobs.
|
||||
func parseFeed(s Source, body []byte) ([]Job, error) {
|
||||
var jobs []Job
|
||||
add := func(id, title, location, url, text, detail string) {
|
||||
if id == "" || title == "" {
|
||||
return
|
||||
}
|
||||
jobs = append(jobs, Job{
|
||||
Key: s.ATS + ":" + s.Slug + ":" + id, Company: s.Company, Title: strings.TrimSpace(title),
|
||||
Location: strings.TrimSpace(location), URL: url, Text: truncate(text, maxPostingChars), DetailURL: detail,
|
||||
})
|
||||
}
|
||||
|
||||
switch s.ATS {
|
||||
case "greenhouse":
|
||||
var d struct {
|
||||
Jobs []struct {
|
||||
ID json.RawMessage `json:"id"`
|
||||
Title string `json:"title"`
|
||||
URL string `json:"absolute_url"`
|
||||
Content string `json:"content"` // HTML, entity-escaped once more
|
||||
Location struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"location"`
|
||||
} `json:"jobs"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, j := range d.Jobs {
|
||||
add(anyID(j.ID), j.Title, j.Location.Name, j.URL, htmlToText(html.UnescapeString(j.Content)), "")
|
||||
}
|
||||
|
||||
case "lever":
|
||||
var d []struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
URL string `json:"hostedUrl"`
|
||||
Plain string `json:"descriptionPlain"`
|
||||
Additional string `json:"additionalPlain"`
|
||||
Categories struct {
|
||||
Location string `json:"location"`
|
||||
} `json:"categories"`
|
||||
Lists []struct {
|
||||
Text string `json:"text"`
|
||||
Content string `json:"content"`
|
||||
} `json:"lists"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, j := range d {
|
||||
parts := []string{j.Plain}
|
||||
for _, l := range j.Lists {
|
||||
parts = append(parts, l.Text+"\n"+htmlToText(l.Content))
|
||||
}
|
||||
add(j.ID, j.Text, j.Categories.Location, j.URL, joinText(append(parts, j.Additional)...), "")
|
||||
}
|
||||
|
||||
case "ashby":
|
||||
var d struct {
|
||||
Jobs []struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Location string `json:"location"`
|
||||
URL string `json:"jobUrl"`
|
||||
Plain string `json:"descriptionPlain"`
|
||||
HTML string `json:"descriptionHtml"`
|
||||
Listed *bool `json:"isListed"`
|
||||
} `json:"jobs"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, j := range d.Jobs {
|
||||
if j.Listed != nil && !*j.Listed {
|
||||
continue
|
||||
}
|
||||
text := j.Plain
|
||||
if strings.TrimSpace(text) == "" {
|
||||
text = htmlToText(j.HTML)
|
||||
}
|
||||
add(j.ID, j.Title, j.Location, j.URL, text, "")
|
||||
}
|
||||
|
||||
case "recruitee":
|
||||
var d struct {
|
||||
Offers []struct {
|
||||
ID json.RawMessage `json:"id"`
|
||||
Title string `json:"title"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
URL string `json:"careers_url"`
|
||||
Description string `json:"description"`
|
||||
Requirements string `json:"requirements"`
|
||||
} `json:"offers"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, j := range d.Offers {
|
||||
add(anyID(j.ID), j.Title, j.City+", "+j.Country, j.URL,
|
||||
joinText(htmlToText(j.Description), htmlToText(j.Requirements)), "")
|
||||
}
|
||||
|
||||
case "smartrecruiters":
|
||||
var d struct {
|
||||
Content []struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Location struct {
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
} `json:"location"`
|
||||
} `json:"content"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, j := range d.Content {
|
||||
add(j.ID, j.Name, j.Location.City+", "+strings.ToUpper(j.Location.Country),
|
||||
"https://jobs.smartrecruiters.com/"+s.Slug+"/"+j.ID, "",
|
||||
"https://api.smartrecruiters.com/v1/companies/"+s.Slug+"/postings/"+j.ID)
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown ATS %q", s.ATS)
|
||||
}
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
// parseSmartDetail reads the description out of a SmartRecruiters posting.
|
||||
func parseSmartDetail(body []byte) (string, error) {
|
||||
var d struct {
|
||||
JobAd struct {
|
||||
Sections map[string]struct {
|
||||
Title string `json:"title"`
|
||||
Text string `json:"text"`
|
||||
} `json:"sections"`
|
||||
} `json:"jobAd"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &d); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var parts []string
|
||||
for _, k := range []string{"companyDescription", "jobDescription", "qualifications", "additionalInformation"} {
|
||||
if s, ok := d.JobAd.Sections[k]; ok {
|
||||
parts = append(parts, s.Title+"\n"+htmlToText(s.Text))
|
||||
}
|
||||
}
|
||||
return truncate(joinText(parts...), maxPostingChars), nil
|
||||
}
|
||||
|
||||
const maxFeedBytes = 64 << 20 // big boards with full descriptions run to tens of MB
|
||||
|
||||
func getJSON(ctx context.Context, client *http.Client, url string) ([]byte, error) {
|
||||
status, body, err := httpGet(ctx, client, url, maxFeedBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if status != http.StatusOK {
|
||||
return nil, fmt.Errorf("HTTP %s", strconv.Itoa(status))
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
// listJobs fetches and parses one company's feed.
|
||||
func listJobs(ctx context.Context, client *http.Client, s Source) ([]Job, error) {
|
||||
u, err := feedURL(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := getJSON(ctx, client, u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseFeed(s, body)
|
||||
}
|
||||
|
||||
// jobText returns the description, fetching the detail document if the feed
|
||||
// did not carry it.
|
||||
func jobText(ctx context.Context, client *http.Client, j Job) (string, error) {
|
||||
if j.Text != "" || j.DetailURL == "" {
|
||||
return j.Text, nil
|
||||
}
|
||||
body, err := getJSON(ctx, client, j.DetailURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return parseSmartDetail(body)
|
||||
}
|
||||
Reference in New Issue
Block a user