Compare commits
14 Commits
cf34889bef
...
v0.5.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b090cb86a5 | ||
|
|
e42df54632 | ||
|
|
0120fdd0e2 | ||
|
|
eab73aec04 | ||
|
|
bd9dca9766 | ||
|
|
56f7d093ef | ||
|
|
62b413c033 | ||
|
|
3adcee2fbe | ||
|
|
e916b5abfc | ||
|
|
211ef64261 | ||
|
|
bb8e2a18ef | ||
|
|
d2cf8c74a2 | ||
|
|
db289cb5c8 | ||
|
|
128c98dfbd |
@@ -224,38 +224,21 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
|
|||||||
func (ntg NTGVision) workingHours(now time.Time) bool {
|
func (ntg NTGVision) workingHours(now time.Time) bool {
|
||||||
// TODO assert M-F 9-4 EST
|
// TODO assert M-F 9-4 EST
|
||||||
now = now.In(time.FixedZone("EST", -5*60*60))
|
now = now.In(time.FixedZone("EST", -5*60*60))
|
||||||
working := config.Get().Brokers.NTG.Working
|
switch now.Weekday() {
|
||||||
logtr.Debugf("ntg.workingHours: now=%s, weekday=%v, hour=%v (ok=%+v)", now.String(), now.Weekday(), now.Hour(), working)
|
case time.Sunday, time.Saturday:
|
||||||
if ok := func() bool {
|
|
||||||
for _, hr := range working.Hours {
|
|
||||||
if now.Hour() == hr {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}(); !ok {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ok := func() bool {
|
switch now.Hour() {
|
||||||
for _, weekday := range working.Weekdays {
|
case 9, 10, 11, 12, 13, 14, 15, 16:
|
||||||
if now.Weekday() == time.Weekday(weekday) {
|
default:
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}(); !ok {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
||||||
if !ntg.workingHours(time.Now()) {
|
if ntg.workingHours(time.Now()) {
|
||||||
lastNtgB, _ := config.Get().DB().Get("ntg_last_search_states")
|
return nil, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc, err := ntg.searcher.searchStates(states)
|
rc, err := ntg.searcher.searchStates(states)
|
||||||
@@ -273,22 +256,12 @@ func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
|||||||
|
|
||||||
var ntgjobs []ntgVisionJob
|
var ntgjobs []ntgVisionJob
|
||||||
err = json.Unmarshal(b, &ntgjobs)
|
err = json.Unmarshal(b, &ntgjobs)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
jobs := make([]Job, len(ntgjobs))
|
jobs := make([]Job, len(ntgjobs))
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
jobs[i] = ntgjobs[i].Job()
|
jobs[i] = ntgjobs[i].Job()
|
||||||
}
|
}
|
||||||
|
return jobs, err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNTGTokenKey() string {
|
func getNTGTokenKey() string {
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
package broker
|
package broker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"local/truckstop/config"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWorkingHoursNTG(t *testing.T) {
|
func TestWorkingHoursNTG(t *testing.T) {
|
||||||
os.Setenv("CONFIG", "../config.json")
|
|
||||||
if err := config.Refresh(nil); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
ntg := NTGVision{}
|
ntg := NTGVision{}
|
||||||
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
||||||
t.Fatal("noon MST not ok")
|
t.Fatal("noon MST not ok")
|
||||||
|
|||||||
@@ -79,10 +79,6 @@
|
|||||||
"UseZips": true,
|
"UseZips": true,
|
||||||
"RadiusMiles": 200,
|
"RadiusMiles": 200,
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"Working": {
|
|
||||||
"Hours": [6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
||||||
"Weekdays": [1, 2, 3, 4, 5]
|
|
||||||
},
|
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"JobInfo": true,
|
"JobInfo": true,
|
||||||
"Mock": true,
|
"Mock": true,
|
||||||
@@ -98,4 +94,4 @@
|
|||||||
"Password": "166647"
|
"Password": "166647"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,10 +83,6 @@
|
|||||||
"Password": "p"
|
"Password": "p"
|
||||||
},
|
},
|
||||||
"NTG": {
|
"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,
|
"Enabled": true,
|
||||||
"JobInfo": true,
|
"JobInfo": true,
|
||||||
"Mock": true,
|
"Mock": true,
|
||||||
|
|||||||
@@ -67,10 +67,6 @@ type Config struct {
|
|||||||
UseZips bool
|
UseZips bool
|
||||||
RadiusMiles int
|
RadiusMiles int
|
||||||
NTG struct {
|
NTG struct {
|
||||||
Working struct {
|
|
||||||
Hours []int
|
|
||||||
Weekdays []int
|
|
||||||
}
|
|
||||||
Enabled bool
|
Enabled bool
|
||||||
JobInfo bool
|
JobInfo bool
|
||||||
Mock bool
|
Mock bool
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -371,7 +371,7 @@ func __main() error {
|
|||||||
logtr.Errorf("failed _main: %v", err)
|
logtr.Errorf("failed _main: %v", err)
|
||||||
}
|
}
|
||||||
if config.Get().Once {
|
if config.Get().Once {
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
todo:
|
todo:
|
||||||
|
- fast exact does not use ID in UID because they spammy
|
||||||
|
- from states to zip codes w/ range
|
||||||
|
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
||||||
- more than NTG; blue one
|
- more than NTG; blue one
|
||||||
- !states emits current state
|
- !states emits current state
|
||||||
- test each !command callbacks to matrix
|
- test each !command callbacks to matrix
|
||||||
@@ -11,11 +14,7 @@ todo:
|
|||||||
subtasks:
|
subtasks:
|
||||||
- banlist criteria like vendors, brokers, metadata
|
- banlist criteria like vendors, brokers, metadata
|
||||||
- set up copy for caleb, broc
|
- set up copy for caleb, broc
|
||||||
- move from main() and make more functions
|
|
||||||
done:
|
done:
|
||||||
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
|
||||||
- from states to zip codes w/ range
|
|
||||||
- fast exact does not use ID in UID because they spammy
|
|
||||||
- fast exact is dumb or...?
|
- fast exact is dumb or...?
|
||||||
- try search ntg by autoinc?
|
- try search ntg by autoinc?
|
||||||
- TEST. Just like, refactor and test to shit.
|
- TEST. Just like, refactor and test to shit.
|
||||||
|
|||||||
33121
zip/testdata/simplemaps_uszips_basicv1.79/uszips.csv
vendored
Executable file
33121
zip/testdata/simplemaps_uszips_basicv1.79/uszips.csv
vendored
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user