Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b090cb86a5 | ||
|
|
e42df54632 | ||
|
|
0120fdd0e2 | ||
|
|
eab73aec04 |
@@ -221,7 +221,26 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
|
|||||||
return jobs, nil
|
return jobs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ntg NTGVision) workingHours(now time.Time) bool {
|
||||||
|
// TODO assert M-F 9-4 EST
|
||||||
|
now = now.In(time.FixedZone("EST", -5*60*60))
|
||||||
|
switch now.Weekday() {
|
||||||
|
case time.Sunday, time.Saturday:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch now.Hour() {
|
||||||
|
case 9, 10, 11, 12, 13, 14, 15, 16:
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
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()) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
rc, err := ntg.searcher.searchStates(states)
|
rc, err := ntg.searcher.searchStates(states)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -334,7 +353,7 @@ func (ntg NTGVision) _searchStates(states []config.State) (io.ReadCloser, error)
|
|||||||
request2, _ := ntg.newRequest(states)
|
request2, _ := ntg.newRequest(states)
|
||||||
requestb, _ := ioutil.ReadAll(request2.Body)
|
requestb, _ := ioutil.ReadAll(request2.Body)
|
||||||
logtr.Debugf("ntg auth bad status: url=%s, status=%v, body=%s, headers=%+v, request=%+v, requestb=%s", request.URL.String(), resp.StatusCode, b, resp.Header, request2, requestb)
|
logtr.Debugf("ntg auth bad status: url=%s, status=%v, body=%s, headers=%+v, request=%+v, requestb=%s", request.URL.String(), resp.StatusCode, b, resp.Header, request2, requestb)
|
||||||
if resp.StatusCode > 400 && resp.StatusCode < 404 {
|
if resp.StatusCode > 400 && resp.StatusCode < 404 || resp.StatusCode == 417 { // TODO wtf is 417 for
|
||||||
logtr.Debugf("ntg auth bad status: err no auth")
|
logtr.Debugf("ntg auth bad status: err no auth")
|
||||||
return nil, ErrNoAuth
|
return nil, ErrNoAuth
|
||||||
}
|
}
|
||||||
|
|||||||
16
broker/ntgvision_test.go
Normal file
16
broker/ntgvision_test.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package broker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWorkingHoursNTG(t *testing.T) {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
if ntg.workingHours(time.Date(2022, 1, 27, 23, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
||||||
|
t.Fatal("midnight MST ok")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,11 +77,11 @@
|
|||||||
"Once": false,
|
"Once": false,
|
||||||
"Brokers": {
|
"Brokers": {
|
||||||
"UseZips": true,
|
"UseZips": true,
|
||||||
"RadiusMiles": 300,
|
"RadiusMiles": 200,
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"Enabled": true,
|
"Enabled": false,
|
||||||
"JobInfo": true,
|
"JobInfo": true,
|
||||||
"Mock": false,
|
"Mock": true,
|
||||||
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
||||||
"LoadPageAPIURIFormat": "https://ntgvision.com/api/v1/load/LoadDetails?loadId=%d",
|
"LoadPageAPIURIFormat": "https://ntgvision.com/api/v1/load/LoadDetails?loadId=%d",
|
||||||
"Username": "noeasyrunstrucking@gmail.com",
|
"Username": "noeasyrunstrucking@gmail.com",
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
},
|
},
|
||||||
"FastExact": {
|
"FastExact": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"Mock": false,
|
"Mock": true,
|
||||||
"Username": "birdman",
|
"Username": "birdman",
|
||||||
"Password": "166647"
|
"Password": "166647"
|
||||||
}
|
}
|
||||||
|
|||||||
57
main.go
57
main.go
@@ -13,6 +13,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -84,9 +85,9 @@ func matrixrecv() error {
|
|||||||
logtr.Debugf("sending help")
|
logtr.Debugf("sending help")
|
||||||
locationHelp := "`!state nc NC nC Nc` set states for self"
|
locationHelp := "`!state nc NC nC Nc` set states for self"
|
||||||
if config.Get().Brokers.UseZips {
|
if config.Get().Brokers.UseZips {
|
||||||
locationHelp = "`!zip 27006 84058` to set zip codes for self"
|
locationHelp = "...`!zip 27006 84058` to set zip codes for self\n...`!radius 100` to set miles radius to 100, 200, or 300"
|
||||||
}
|
}
|
||||||
help := fmt.Sprintf("commands:\n...`!help` print this help\n...%s\n\nrun a command for someone else: `!zip 2022-12-31 @caleb`", locationHelp)
|
help := fmt.Sprintf("commands:\n...`!help` print this help\n%s\n\nrun a command for someone else: `!zip 2022-12-31 @caleb`", locationHelp)
|
||||||
if err := sender.Send(help); err != nil {
|
if err := sender.Send(help); err != nil {
|
||||||
logtr.Errorf("failed to send help: %v", err)
|
logtr.Errorf("failed to send help: %v", err)
|
||||||
} else {
|
} else {
|
||||||
@@ -151,6 +152,31 @@ func matrixrecv() error {
|
|||||||
}
|
}
|
||||||
setNewStates(states)
|
setNewStates(states)
|
||||||
}()
|
}()
|
||||||
|
func() {
|
||||||
|
logtr.Verbosef("looking for radius")
|
||||||
|
db := config.Get().DB()
|
||||||
|
var radius *int
|
||||||
|
for _, msg := range messages {
|
||||||
|
key := fmt.Sprintf("radius_%d", msg.Timestamp.Unix())
|
||||||
|
if !strings.HasPrefix(msg.Content, "!radius ") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||||
|
cmd := msg.Content
|
||||||
|
for strings.HasPrefix(cmd, "!radius ") {
|
||||||
|
cmd = strings.TrimPrefix(cmd, "!radius ")
|
||||||
|
}
|
||||||
|
n, err := strconv.Atoi(strings.TrimSpace(cmd))
|
||||||
|
if err == nil {
|
||||||
|
radius = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||||
|
logtr.Errorf("failed to mark radius gathered @%s: %v", key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setNewRadius(radius)
|
||||||
|
}()
|
||||||
func() {
|
func() {
|
||||||
logtr.Verbosef("looking for pauses")
|
logtr.Verbosef("looking for pauses")
|
||||||
db := config.Get().DB()
|
db := config.Get().DB()
|
||||||
@@ -183,6 +209,33 @@ func matrixrecv() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setNewRadius(radius *int) {
|
||||||
|
if radius == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sender := message.NewMatrix()
|
||||||
|
logtr.Debugf("set new radius: %d", *radius)
|
||||||
|
acceptable := map[int]struct{}{
|
||||||
|
100: struct{}{},
|
||||||
|
200: struct{}{},
|
||||||
|
300: struct{}{},
|
||||||
|
}
|
||||||
|
if _, ok := acceptable[*radius]; !ok {
|
||||||
|
sender.Send(fmt.Sprintf("radius of %v is not among acceptable %+v", *radius, acceptable))
|
||||||
|
logtr.Debugf("bad radius, not setting: %d", *radius)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf := *config.Get()
|
||||||
|
if conf.Brokers.RadiusMiles == *radius {
|
||||||
|
logtr.Debugf("noop radius, not setting: %d", *radius)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf.Brokers.RadiusMiles = *radius
|
||||||
|
logtr.Infof("updating config new pauses: %+v", conf)
|
||||||
|
config.Set(conf)
|
||||||
|
sender.Send(fmt.Sprintf("now using radius of %d mi for zip code search", *radius))
|
||||||
|
}
|
||||||
|
|
||||||
func setNewPauses(pauses map[string]time.Time) {
|
func setNewPauses(pauses map[string]time.Time) {
|
||||||
if len(pauses) == 0 {
|
if len(pauses) == 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package zip
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"local/truckstop/logtr"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -44,6 +45,7 @@ func init() {
|
|||||||
State: state,
|
State: state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logtr.Infof("loaded %d zip codes", len(zips))
|
||||||
}
|
}
|
||||||
|
|
||||||
func alphafy(s string) string {
|
func alphafy(s string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user