Compare commits

..

18 Commits

Author SHA1 Message Date
bel
1a072fee59 Merge branch 'master' of http://gogs.scratch.com:59515/bel/truckstop 2022-01-29 18:44:21 -07:00
bel
c4213e697d fuck backwards bool 2022-01-29 18:44:13 -07:00
bel
934a306bc9 log 2022-01-29 18:40:13 -07:00
Bel LaPointe
82bdbb1f3b todo 2022-01-27 20:18:13 -07:00
Bel LaPointe
b090cb86a5 fix offset to not need system timezone 2022-01-27 20:04:31 -07:00
Bel LaPointe
e42df54632 only do ntgvision searches 9-4 EST because 417s mean unauth until forced pw reset 2022-01-27 19:53:50 -07:00
Bel LaPointe
0120fdd0e2 accept !radius for miles radius search 2022-01-27 19:21:03 -07:00
Bel LaPointe
eab73aec04 include one very nice log 2022-01-27 19:00:40 -07:00
Bel LaPointe
bd9dca9766 remove unwanted from help, only print !zip or !state as configured 2022-01-27 18:53:56 -07:00
Bel LaPointe
56f7d093ef fix typo in config.json for == in query 2022-01-27 18:49:05 -07:00
Bel LaPointe
62b413c033 debug to verbose logs 2022-01-27 18:46:59 -07:00
Bel LaPointe
3adcee2fbe whoosp backwards if body 2022-01-27 18:41:58 -07:00
Bel LaPointe
e916b5abfc job filters by zip or state depending on config 2022-01-27 18:35:40 -07:00
Bel LaPointe
211ef64261 support logging zip changes 2022-01-27 18:27:01 -07:00
Bel LaPointe
bb8e2a18ef main will search zips if Broker.UseZips, ntg does its own filtering by city-state dist from search-zips 2022-01-27 18:20:52 -07:00
Bel LaPointe
d2cf8c74a2 ntgvision maps zips to states then does same query 2022-01-27 18:14:49 -07:00
Bel LaPointe
db289cb5c8 impl and test zip.Get, MilesTo, GetStatesWithin, FromCityState 2022-01-27 18:11:11 -07:00
Bel LaPointe
128c98dfbd impl zip.Get for translating zip to info and calc dist 2022-01-27 17:58:00 -07:00
7 changed files with 33131 additions and 54 deletions

View File

@@ -224,26 +224,14 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
func (ntg NTGVision) workingHours(now time.Time) bool {
// TODO assert M-F 9-4 EST
now = now.In(time.FixedZone("EST", -5*60*60))
working := config.Get().Brokers.NTG.Working
logtr.Debugf("ntg.workingHours: now=%s, weekday=%v, hour=%v (ok=%+v)", now.String(), now.Weekday(), now.Hour(), working)
if ok := func() bool {
for _, hr := range working.Hours {
if now.Hour() == hr {
return true
}
}
return false
}(); !ok {
logtr.Debugf("ntg.workingHours: %s: weekday=%v (sun=%v, sat=%v), hour=%v (ok=9..16)", now.String(), now.Weekday(), time.Sunday, time.Saturday, now.Hour())
switch now.Weekday() {
case time.Sunday, time.Saturday:
return false
}
if ok := func() bool {
for _, weekday := range working.Weekdays {
if now.Weekday() == time.Weekday(weekday) {
return true
}
}
return false
}(); !ok {
switch now.Hour() {
case 9, 10, 11, 12, 13, 14, 15, 16:
default:
return false
}
return true
@@ -251,11 +239,7 @@ func (ntg NTGVision) workingHours(now time.Time) bool {
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
if !ntg.workingHours(time.Now()) {
lastNtgB, _ := config.Get().DB().Get("ntg_last_search_states")
var jobs []Job
json.Unmarshal(lastNtgB, &jobs)
logtr.Verbosef("ntg.SearchStates: outside of working hours so returning ntg_last_search_states: %+v", jobs)
return jobs, nil
return nil, nil
}
rc, err := ntg.searcher.searchStates(states)
@@ -273,22 +257,12 @@ func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
var ntgjobs []ntgVisionJob
err = json.Unmarshal(b, &ntgjobs)
if err != nil {
return nil, err
}
jobs := make([]Job, len(ntgjobs))
for i := range jobs {
jobs[i] = ntgjobs[i].Job()
}
jobsB, err := json.Marshal(jobs)
if err == nil {
config.Get().DB().Set("ntg_last_search_states", jobsB)
logtr.Verbosef("ntg.SearchStates: in working hours so setting ntg_last_search_states: %+v", jobs)
}
return jobs, nil
return jobs, err
}
func getNTGTokenKey() string {

View File

@@ -1,17 +1,11 @@
package broker
import (
"local/truckstop/config"
"os"
"testing"
"time"
)
func TestWorkingHoursNTG(t *testing.T) {
os.Setenv("CONFIG", "../config.json")
if err := config.Refresh(nil); err != nil {
t.Fatal(err)
}
ntg := NTGVision{}
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
t.Fatal("noon MST not ok")

View File

@@ -79,10 +79,6 @@
"UseZips": true,
"RadiusMiles": 200,
"NTG": {
"Working": {
"Hours": [6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
"Weekdays": [1, 2, 3, 4, 5]
},
"Enabled": false,
"JobInfo": true,
"Mock": true,
@@ -98,4 +94,4 @@
"Password": "166647"
}
}
}
}

View File

@@ -83,10 +83,6 @@
"Password": "p"
},
"NTG": {
"Working": {
"Hours": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
"Weekdays": [0, 1, 2, 3, 4, 5, 6]
},
"Enabled": true,
"JobInfo": true,
"Mock": true,

View File

@@ -67,10 +67,6 @@ type Config struct {
UseZips bool
RadiusMiles int
NTG struct {
Working struct {
Hours []int
Weekdays []int
}
Enabled bool
JobInfo bool
Mock bool

View File

@@ -371,7 +371,7 @@ func __main() error {
logtr.Errorf("failed _main: %v", err)
}
if config.Get().Once {
time.Sleep(10 * time.Second)
time.Sleep(3 * time.Second)
return err
}
if err != nil {

File diff suppressed because it is too large Load Diff