Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e42df54632 | ||
|
|
0120fdd0e2 | ||
|
|
eab73aec04 |
@@ -221,7 +221,30 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (ntg NTGVision) workingHours(now time.Time) bool {
|
||||
// TODO assert M-F 9-4 EST
|
||||
location, err := time.LoadLocation("EST")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
now = now.In(location)
|
||||
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) {
|
||||
if ntg.workingHours(time.Now()) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
rc, err := ntg.searcher.searchStates(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -334,7 +357,7 @@ func (ntg NTGVision) _searchStates(states []config.State) (io.ReadCloser, error)
|
||||
request2, _ := ntg.newRequest(states)
|
||||
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)
|
||||
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")
|
||||
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.Local)) {
|
||||
t.Fatal("noon MST not ok")
|
||||
}
|
||||
if ntg.workingHours(time.Date(2022, 1, 27, 23, 0, 0, 0, time.Local)) {
|
||||
t.Fatal("midnight MST ok")
|
||||
}
|
||||
}
|
||||
@@ -77,11 +77,11 @@
|
||||
"Once": false,
|
||||
"Brokers": {
|
||||
"UseZips": true,
|
||||
"RadiusMiles": 300,
|
||||
"RadiusMiles": 200,
|
||||
"NTG": {
|
||||
"Enabled": true,
|
||||
"Enabled": false,
|
||||
"JobInfo": true,
|
||||
"Mock": false,
|
||||
"Mock": true,
|
||||
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
||||
"LoadPageAPIURIFormat": "https://ntgvision.com/api/v1/load/LoadDetails?loadId=%d",
|
||||
"Username": "noeasyrunstrucking@gmail.com",
|
||||
@@ -89,7 +89,7 @@
|
||||
},
|
||||
"FastExact": {
|
||||
"Enabled": true,
|
||||
"Mock": false,
|
||||
"Mock": true,
|
||||
"Username": "birdman",
|
||||
"Password": "166647"
|
||||
}
|
||||
|
||||
57
main.go
57
main.go
@@ -13,6 +13,7 @@ import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -84,9 +85,9 @@ func matrixrecv() error {
|
||||
logtr.Debugf("sending help")
|
||||
locationHelp := "`!state nc NC nC Nc` set states for self"
|
||||
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 {
|
||||
logtr.Errorf("failed to send help: %v", err)
|
||||
} else {
|
||||
@@ -151,6 +152,31 @@ func matrixrecv() error {
|
||||
}
|
||||
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() {
|
||||
logtr.Verbosef("looking for pauses")
|
||||
db := config.Get().DB()
|
||||
@@ -183,6 +209,33 @@ func matrixrecv() error {
|
||||
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) {
|
||||
if len(pauses) == 0 {
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package zip
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"local/truckstop/logtr"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -44,6 +45,7 @@ func init() {
|
||||
State: state,
|
||||
}
|
||||
}
|
||||
logtr.Infof("loaded %d zip codes", len(zips))
|
||||
}
|
||||
|
||||
func alphafy(s string) string {
|
||||
|
||||
Reference in New Issue
Block a user