Bel LaPointe 2022-01-27 16:24:21 -07:00
commit c56acbc120
6 changed files with 41 additions and 17 deletions

View File

@ -92,13 +92,21 @@ func (fe FastExact) setHeaders(req *http.Request) {
} }
func (fe FastExact) search(states []config.State) ([]Job, error) { func (fe FastExact) search(states []config.State) ([]Job, error) {
var result []Job var jobs []Job
for _, state := range states { for _, state := range states {
jobs, err := fe.searchOne(state) subjobs, err := fe.searchOne(state)
if err != nil { if err != nil {
return nil, err return nil, err
} }
result = append(result, jobs...) jobs = append(jobs, subjobs...)
}
dedupeJobs := map[string]Job{}
for _, job := range jobs {
dedupeJobs[job.UID()] = job
}
result := []Job{}
for _, job := range dedupeJobs {
result = append(result, job)
} }
return result, nil return result, nil
} }
@ -123,7 +131,7 @@ func (fe FastExact) newRequest(state config.State) (*http.Request, error) {
} }
req, err := http.NewRequest( req, err := http.NewRequest(
http.MethodGet, http.MethodGet,
"https://www.fastexact.com/secure/index.php?page=ajaxListJobs&action=ajax&zipcode="+zip+"&records_per_page=50&distance=300&st_loc_zip=8", "https://www.fastexact.com/secure/index.php?page=ajaxListJobs&action=ajax&zipcode="+zip+"&records_per_page=50&distance="+strconv.Itoa(config.Get().Brokers.FastExact.RadiusMiles)+"&st_loc_zip=8",
nil, nil,
) )
if err != nil { if err != nil {
@ -236,8 +244,8 @@ func (mock mockFastExactDoer) doRequest(req *http.Request) (*http.Response, erro
if req.URL.Query().Get("records_per_page") != "50" { if req.URL.Query().Get("records_per_page") != "50" {
return nil, errors.New("bad query: records_per_page should be 50") return nil, errors.New("bad query: records_per_page should be 50")
} }
if req.URL.Query().Get("distance") != "300" { if req.URL.Query().Get("distance") != strconv.Itoa(config.Get().Brokers.FastExact.RadiusMiles) {
return nil, errors.New("bad query: distance should be 300") return nil, errors.New("bad query: distance should be as configured")
} }
if req.URL.Query().Get("zipcode") == "" { if req.URL.Query().Get("zipcode") == "" {
return nil, errors.New("bad query: zip code empty") return nil, errors.New("bad query: zip code empty")

View File

@ -65,8 +65,8 @@ func TestFastExactSearch(t *testing.T) {
_ = db _ = db
if jobs, err := fe.search([]config.State{config.State("NC"), config.State("SC")}); err != nil { if jobs, err := fe.search([]config.State{config.State("NC"), config.State("SC")}); err != nil {
t.Fatal(err) t.Fatal(err)
} else if len(jobs) != 20 { } else if len(jobs) != 10 {
t.Fatal(jobs) t.Fatal(len(jobs))
} else { } else {
for _, job := range jobs { for _, job := range jobs {
if job.ID == "" { if job.ID == "" {

View File

@ -72,11 +72,14 @@
"Once": true, "Once": true,
"Brokers": { "Brokers": {
"FastExact": { "FastExact": {
"Mock": false, "RadiusMiles": 100,
"Username": "birdman", "Enabled": true,
"Password": "166647" "Mock": true,
"Username": "u",
"Password": "p"
}, },
"NTG": { "NTG": {
"Enabled": true,
"JobInfo": true, "JobInfo": true,
"Mock": true, "Mock": true,
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d", "LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",

View File

@ -72,11 +72,14 @@
"Once": true, "Once": true,
"Brokers": { "Brokers": {
"FastExact": { "FastExact": {
"RadiusMiles": 100,
"Enabled": true,
"Mock": true, "Mock": true,
"Username": "u", "Username": "u",
"Password": "p" "Password": "p"
}, },
"NTG": { "NTG": {
"Enabled": true,
"JobInfo": true, "JobInfo": true,
"Mock": true, "Mock": true,
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d", "LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",

View File

@ -65,6 +65,7 @@ type Config struct {
Once bool Once bool
Brokers struct { Brokers struct {
NTG struct { NTG struct {
Enabled bool
JobInfo bool JobInfo bool
Mock bool Mock bool
LoadPageURIFormat string LoadPageURIFormat string
@ -73,6 +74,8 @@ type Config struct {
Password string Password string
} }
FastExact struct { FastExact struct {
Enabled bool
RadiusMiles int
Mock bool Mock bool
Username string Username string
Password string Password string

13
main.go
View File

@ -314,9 +314,16 @@ func once() error {
func getJobs() ([]broker.Job, error) { func getJobs() ([]broker.Job, error) {
states := config.AllStates() states := config.AllStates()
ntg := broker.NewNTGVision() brokers := []broker.Broker{}
fe := broker.NewFastExact() if config.Get().Brokers.NTG.Enabled {
brokers := []broker.Broker{ntg, fe} logtr.Debugf("NTG enabled")
brokers = append(brokers, broker.NewNTGVision())
}
if config.Get().Brokers.FastExact.Enabled {
logtr.Debugf("FastExact enabled")
brokers = append(brokers, broker.NewFastExact())
}
logtr.Debugf("brokers=%+v", brokers)
jobs := []broker.Job{} jobs := []broker.Job{}
for _, broker := range brokers { for _, broker := range brokers {
somejobs, err := broker.Search(states) somejobs, err := broker.Search(states)