Compare commits
No commits in common. "master" and "v0.3.1" have entirely different histories.
|
|
@ -3,9 +3,9 @@ package broker
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gogs.inhome.blapointe.com/local/storage"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"local/storage"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -20,8 +20,7 @@ var authlimiter = rate.NewLimiter(rate.Limit(1.0/60.0), 1)
|
|||
var limiter = rate.NewLimiter(rate.Limit(1.0/20.0), 1)
|
||||
|
||||
type Broker interface {
|
||||
SearchStates([]config.State) ([]Job, error)
|
||||
SearchZips([]string) ([]Job, error)
|
||||
Search([]config.State) ([]Job, error)
|
||||
}
|
||||
|
||||
func do(r *http.Request) (*http.Response, error) {
|
||||
|
|
@ -43,14 +42,9 @@ func _do(db storage.DB, r *http.Request) (*http.Response, error) {
|
|||
logtr.Errorf("failed to get cookies: %v", err)
|
||||
} else {
|
||||
logtr.Verbosef("got cookies for %s: %+v", cookieJarKey, cookies)
|
||||
cookieV := strings.Join(r.Header["Cookie"], "; ")
|
||||
for _, cookie := range cookies {
|
||||
if len(cookieV) > 0 {
|
||||
cookieV += "; "
|
||||
}
|
||||
cookieV += cookie
|
||||
r.Header.Add("Cookie", cookie)
|
||||
}
|
||||
r.Header.Set("Cookie", cookieV)
|
||||
}
|
||||
logtr.Verbosef("_do: %+v", r)
|
||||
resp, err := client.Do(r)
|
||||
|
|
@ -77,19 +71,11 @@ func setCookies(db storage.DB, host string, resp *http.Response) error {
|
|||
nameValues := [][2]string{}
|
||||
old, _ := getCookies(db, host)
|
||||
for _, value := range old {
|
||||
if len(value) == 0 {
|
||||
continue
|
||||
}
|
||||
name := strings.Split(value, "=")[0]
|
||||
value := strings.Split(value, ";")[0]
|
||||
nameValues = append(nameValues, [2]string{name, value})
|
||||
}
|
||||
for _, cookie := range resp.Header["Set-Cookie"] {
|
||||
if len(cookie) == 0 {
|
||||
continue
|
||||
}
|
||||
name := strings.Split(cookie, "=")[0]
|
||||
value := strings.Split(cookie, ";")[0]
|
||||
for _, value := range resp.Header["Set-Cookie"] {
|
||||
name := strings.Split(value, "=")[0]
|
||||
found := false
|
||||
for i := range nameValues {
|
||||
if nameValues[i][0] == name {
|
||||
|
|
@ -103,9 +89,6 @@ func setCookies(db storage.DB, host string, resp *http.Response) error {
|
|||
}
|
||||
result := []string{}
|
||||
for i := range nameValues {
|
||||
if len(nameValues[i][1]) == 0 {
|
||||
continue
|
||||
}
|
||||
result = append(result, nameValues[i][1])
|
||||
}
|
||||
logtr.Verbosef("setting cookies for %s: %+v", host, result)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ package broker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"gogs.inhome.blapointe.com/local/storage"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"local/storage"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
|
|
@ -15,15 +14,12 @@ import (
|
|||
)
|
||||
|
||||
func TestBrokerInterface(t *testing.T) {
|
||||
logtr.SetLevel(logtr.SOS)
|
||||
var b Broker
|
||||
b = FastExact{}
|
||||
b = NTGVision{}
|
||||
_ = b
|
||||
}
|
||||
|
||||
func TestDoCookies(t *testing.T) {
|
||||
logtr.SetLevel(logtr.SOS)
|
||||
limiter = rate.NewLimiter(rate.Limit(20.0), 1)
|
||||
calls := 0
|
||||
db := storage.NewMap()
|
||||
|
|
@ -32,9 +28,9 @@ func TestDoCookies(t *testing.T) {
|
|||
if calls != 1 {
|
||||
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
t.Error("cookie not set as latest: " + fmt.Sprint(r.Header["Cookie"]))
|
||||
t.Error("cookie not set as latest")
|
||||
}
|
||||
if strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") {
|
||||
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
t.Error("cookie not expiration: ", r.Header["Cookie"])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,318 +0,0 @@
|
|||
package broker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/storage"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
type FastExact struct {
|
||||
doer interface {
|
||||
doRequest(*http.Request) (*http.Response, error)
|
||||
}
|
||||
}
|
||||
|
||||
func NewFastExact() FastExact {
|
||||
fe := FastExact{}
|
||||
fe.doer = fe
|
||||
if config.Get().Brokers.FastExact.Mock {
|
||||
fe = fe.WithMock()
|
||||
}
|
||||
return fe
|
||||
}
|
||||
|
||||
func (fe FastExact) WithMock() FastExact {
|
||||
fe.doer = mockFastExactDoer{}
|
||||
return fe
|
||||
}
|
||||
|
||||
func (fe FastExact) SearchZips(zips []string) ([]Job, error) {
|
||||
jobs, err := fe.searchZips(zips)
|
||||
if err == ErrNoAuth {
|
||||
if err := fe.login(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jobs, err = fe.searchZips(zips)
|
||||
}
|
||||
return jobs, err
|
||||
}
|
||||
|
||||
func (fe FastExact) SearchStates(states []config.State) ([]Job, error) {
|
||||
jobs, err := fe.searchStates(states)
|
||||
if err == ErrNoAuth {
|
||||
if err := fe.login(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jobs, err = fe.searchStates(states)
|
||||
}
|
||||
return jobs, err
|
||||
}
|
||||
|
||||
func (fe FastExact) login() error {
|
||||
conf := config.Get()
|
||||
return fe._login(conf.Brokers.FastExact.Username, conf.Brokers.FastExact.Password, conf.DB())
|
||||
}
|
||||
|
||||
func (fe FastExact) _login(username, password string, db storage.DB) error {
|
||||
req, err := http.NewRequest(
|
||||
http.MethodPost,
|
||||
`https://www.fastexact.com/secure/index.php?page=userLogin`,
|
||||
strings.NewReader(fmt.Sprintf(
|
||||
`user_name=%s&user_password=%s&buttonSubmit=Login`,
|
||||
username,
|
||||
password,
|
||||
)),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fe.setHeaders(req)
|
||||
|
||||
db.Set("cookies_"+req.URL.Host, nil)
|
||||
resp, err := fe.doer.doRequest(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("bad status logging into fast exact: %d: %s", resp.StatusCode, b)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fe FastExact) setHeaders(req *http.Request) {
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0")
|
||||
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")
|
||||
req.Header.Set("Accept-Language", "en-US,en;q=0.5")
|
||||
req.Header.Set("Accept-Encoding", "gzip, deflate, br")
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
|
||||
func (fe FastExact) searchZips(zips []string) ([]Job, error) {
|
||||
var jobs []Job
|
||||
for _, zip := range zips {
|
||||
subjobs, err := fe.searchOneZip(zip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jobs = append(jobs, subjobs...)
|
||||
}
|
||||
return fe.dedupeJobs(jobs), nil
|
||||
}
|
||||
|
||||
func (fe FastExact) searchStates(states []config.State) ([]Job, error) {
|
||||
var jobs []Job
|
||||
for _, state := range states {
|
||||
subjobs, err := fe.searchOneState(state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jobs = append(jobs, subjobs...)
|
||||
}
|
||||
return fe.dedupeJobs(jobs), nil
|
||||
}
|
||||
|
||||
func (fe FastExact) dedupeJobs(jobs []Job) []Job {
|
||||
sort.Slice(jobs, func(i, j int) bool {
|
||||
return jobs[i].UID() < jobs[j].UID()
|
||||
})
|
||||
dedupeJobs := map[string]Job{}
|
||||
for _, job := range jobs {
|
||||
dedupeJobs[strings.ReplaceAll(job.UID(), job.ID, "")] = job
|
||||
}
|
||||
result := []Job{}
|
||||
for _, job := range dedupeJobs {
|
||||
result = append(result, job)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (fe FastExact) searchOneZip(zip string) ([]Job, error) {
|
||||
req, err := fe.newRequest(zip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := fe.doer.doRequest(req)
|
||||
logtr.Verbosef("req: %+v => resp: %+v", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return fe.parse(resp)
|
||||
}
|
||||
|
||||
func (fe FastExact) searchOneState(state config.State) ([]Job, error) {
|
||||
req, err := fe.newRequestWithState(state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := fe.doer.doRequest(req)
|
||||
logtr.Verbosef("req: %+v => resp: %+v", req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return fe.parse(resp)
|
||||
}
|
||||
|
||||
func (fe FastExact) newRequestWithState(state config.State) (*http.Request, error) {
|
||||
zip, ok := config.States[state]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no configured zip for %s", state)
|
||||
}
|
||||
return fe.newRequest(zip)
|
||||
}
|
||||
|
||||
func (fe FastExact) newRequest(zip string) (*http.Request, error) {
|
||||
req, err := http.NewRequest(
|
||||
http.MethodGet,
|
||||
"https://www.fastexact.com/secure/index.php?page=ajaxListJobs&action=ajax&zipcode="+zip+"&records_per_page=50&distance="+strconv.Itoa(config.Get().Brokers.RadiusMiles)+"&st_loc_zip=8",
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fe.setHeaders(req)
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (fe FastExact) doRequest(req *http.Request) (*http.Response, error) {
|
||||
resp, err := do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
logtr.Errorf("fastExact bad status: %d: %s", resp.StatusCode, b)
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 404 {
|
||||
return nil, ErrNoAuth
|
||||
}
|
||||
return nil, fmt.Errorf("bad status from FastExact: %d: %s", resp.StatusCode, b)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (fe FastExact) parse(resp *http.Response) ([]Job, error) {
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
if !bytes.HasPrefix(bytes.TrimSpace(b), []byte("<")) {
|
||||
gzip, err := gzip.NewReader(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, _ = ioutil.ReadAll(gzip)
|
||||
}
|
||||
if bytes.Contains(b, []byte(`<script>window.location.href='index.php'</script>`)) {
|
||||
return nil, ErrNoAuth
|
||||
}
|
||||
logtr.Verbosef("fe.parse %s", b)
|
||||
resp.Body = io.NopCloser(bytes.NewReader(b))
|
||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]Job, 0)
|
||||
doc.Find("#list table tr").Each(func(i int, s *goquery.Selection) {
|
||||
columns := []string{}
|
||||
s.Find("td").Each(func(i int, s *goquery.Selection) {
|
||||
if s.Nodes[0].LastChild != nil && len(s.Nodes[0].LastChild.Attr) > 0 {
|
||||
attrs := s.Nodes[0].LastChild.Attr
|
||||
columns = append(columns, attrs[len(attrs)-1].Val)
|
||||
} else {
|
||||
columns = append(columns, s.Text())
|
||||
}
|
||||
})
|
||||
if len(columns) < 9 {
|
||||
return
|
||||
}
|
||||
job := Job{
|
||||
ID: columns[0],
|
||||
URI: columns[8],
|
||||
}
|
||||
job.Pickup.Date, _ = time.ParseInLocation("02-Jan-2006 15:04:05", columns[7], time.Local)
|
||||
job.Pickup.City = strings.Title(strings.ToLower(strings.Split(columns[1], ",")[0]))
|
||||
if strings.Contains(columns[1], ",") {
|
||||
job.Pickup.State = strings.Title(strings.Split(strings.Split(columns[1], ",")[1], " ")[1])
|
||||
}
|
||||
|
||||
job.Dropoff.Date = job.Pickup.Date
|
||||
job.Dropoff.City = strings.Title(strings.ToLower(strings.Split(columns[2], ",")[0]))
|
||||
if strings.Contains(columns[2], ",") {
|
||||
job.Dropoff.State = strings.Title(strings.Split(strings.Split(columns[2], ",")[1], " ")[1])
|
||||
}
|
||||
|
||||
job.Miles, _ = strconv.Atoi(columns[3])
|
||||
if strings.Contains(columns[4], "/") {
|
||||
weight, _ := strconv.ParseFloat(strings.TrimSpace(strings.Split(columns[4], "/")[1]), 32)
|
||||
job.Weight = int(weight)
|
||||
}
|
||||
|
||||
job.Meta = fmt.Sprintf(`dimensions:%s`, strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(columns[5], " ", ""), "\n", "")))
|
||||
|
||||
logtr.Verbosef("fe.parse %+v => %+v", columns, job)
|
||||
|
||||
result = append(result, job)
|
||||
})
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type mockFastExactDoer struct{}
|
||||
|
||||
func (mock mockFastExactDoer) doRequest(req *http.Request) (*http.Response, error) {
|
||||
if req.URL.Path != "/secure/index.php" {
|
||||
return nil, errors.New("bad path")
|
||||
}
|
||||
switch req.URL.Query().Get("page") {
|
||||
case "userLogin":
|
||||
if b, _ := ioutil.ReadAll(req.Body); !bytes.Equal(b, []byte(`user_name=u&user_password=p&buttonSubmit=Login`)) {
|
||||
return nil, errors.New("bad req body")
|
||||
}
|
||||
return &http.Response{
|
||||
Status: http.StatusText(http.StatusOK),
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Set-Cookie": []string{"PHPSESSID=SessionFromLogin; path=/"}},
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, nil
|
||||
case "ajaxListJobs":
|
||||
if req.URL.Query().Get("action") != "ajax" {
|
||||
return nil, errors.New("bad query: action should be ajax")
|
||||
}
|
||||
if req.URL.Query().Get("records_per_page") != "50" {
|
||||
return nil, errors.New("bad query: records_per_page should be 50")
|
||||
}
|
||||
if req.URL.Query().Get("distance") != strconv.Itoa(config.Get().Brokers.RadiusMiles) {
|
||||
return nil, errors.New("bad query: distance should be as configured")
|
||||
}
|
||||
if req.URL.Query().Get("zipcode") == "" {
|
||||
return nil, errors.New("bad query: zip code empty")
|
||||
}
|
||||
b, err := ioutil.ReadFile("./testdata/fastexact_search.xml")
|
||||
if err != nil {
|
||||
b, err = ioutil.ReadFile("./broker/testdata/fastexact_search.xml")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Response{
|
||||
Status: http.StatusText(http.StatusOK),
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Set-Cookie": []string{"PHPSESSID=SessionFromSearch; path=/"}},
|
||||
Body: io.NopCloser(bytes.NewReader(b)),
|
||||
}, nil
|
||||
}
|
||||
return nil, errors.New("bad query")
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
package broker
|
||||
|
||||
import (
|
||||
"gogs.inhome.blapointe.com/local/storage"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
func TestFastExactReal(t *testing.T) {
|
||||
if os.Getenv("INTEGRATION_FAST_EXACT") == "" {
|
||||
t.Skip("$INTEGRATION_FAST_EXACT not set")
|
||||
}
|
||||
os.Setenv("CONFIG", "../config.json")
|
||||
if err := config.Refresh(nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conf := config.Get()
|
||||
conf.Storage = []string{"files", path.Join(t.TempDir(), "storage")}
|
||||
os.Setenv("CONFIG", path.Join(t.TempDir(), "config.json"))
|
||||
config.Set(*conf)
|
||||
if err := config.Refresh(nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
states := []config.State{
|
||||
config.State("NC"),
|
||||
}
|
||||
|
||||
fe := NewFastExact()
|
||||
if err := fe.login(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jobs, err := fe.searchStates(states)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Logf("%d", len(jobs))
|
||||
for i := range jobs {
|
||||
t.Logf("[%d] %+v", i, jobs[i])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFastExactLogin(t *testing.T) {
|
||||
logtr.SetLevel(logtr.SOS)
|
||||
limiter = rate.NewLimiter(rate.Limit(60.0), 1)
|
||||
fe := NewFastExact().WithMock()
|
||||
_ = fe
|
||||
db := storage.NewMap()
|
||||
if err := fe._login("u", "p", db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFastExactSearchStates(t *testing.T) {
|
||||
logtr.SetLevel(logtr.SOS)
|
||||
limiter = rate.NewLimiter(rate.Limit(60.0), 1)
|
||||
fe := NewFastExact().WithMock()
|
||||
_ = fe
|
||||
db := storage.NewMap()
|
||||
_ = db
|
||||
if jobs, err := fe.searchStates([]config.State{config.State("NC"), config.State("SC")}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(jobs) != 9 {
|
||||
t.Fatal(len(jobs))
|
||||
} else {
|
||||
for _, job := range jobs {
|
||||
if job.ID == "" {
|
||||
t.Error(job)
|
||||
} else if job.Miles == 0 {
|
||||
t.Error(job)
|
||||
} else if job.URI == "" {
|
||||
t.Error(job)
|
||||
} else if job.Meta == "" {
|
||||
t.Error(job)
|
||||
} else if job.Weight == 0 {
|
||||
t.Error(job)
|
||||
} else if job.Pickup.Date.IsZero() {
|
||||
t.Error(job)
|
||||
} else if job.Pickup.Date != job.Dropoff.Date {
|
||||
t.Error(job)
|
||||
} else if job.Dropoff.State == "" {
|
||||
t.Error(job)
|
||||
} else if job.Dropoff.City == "" {
|
||||
t.Error(job)
|
||||
} else if job.Pickup.State == "" {
|
||||
t.Error(job)
|
||||
} else if job.Pickup.City == "" {
|
||||
t.Error(job)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,8 @@ package broker
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/zip"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -86,17 +86,9 @@ func (j Job) FormatMultilineText() string {
|
|||
}
|
||||
out := ""
|
||||
clients := config.Clients(j.Pickup.Date)
|
||||
useZip := config.Get().Brokers.UseZips
|
||||
zipRadius := config.Get().Brokers.RadiusMiles
|
||||
jobZip := zip.FromCityState(j.Pickup.City, j.Pickup.State)
|
||||
for k := range clients {
|
||||
should := strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State)
|
||||
if useZip {
|
||||
for _, z := range clients[k].Zips {
|
||||
should = should || zip.Get(z).MilesTo(jobZip) <= zipRadius
|
||||
}
|
||||
}
|
||||
if should {
|
||||
logtr.Debugf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
|
||||
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
|
||||
if len(out) > 0 {
|
||||
out += "\n"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,16 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/zip"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NTGVision struct {
|
||||
searcher interface {
|
||||
searchStates(states []config.State) (io.ReadCloser, error)
|
||||
searchJobReadCloser(id int64) (io.ReadCloser, error)
|
||||
search(states []config.State) (io.ReadCloser, error)
|
||||
searchJob(id int64) (io.ReadCloser, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +96,7 @@ func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
|||
return ntgJob.jobinfo, nil
|
||||
}
|
||||
ntg := NewNTGVision()
|
||||
ji, err := ntg.searchJob(ntgJob.ID)
|
||||
ji, err := ntg.SearchJob(ntgJob.ID)
|
||||
if err == nil {
|
||||
ntgJob.jobinfo = ji
|
||||
b, err := json.Marshal(ntgJob.jobinfo)
|
||||
|
|
@ -108,7 +107,7 @@ func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
|||
return ji, err
|
||||
}
|
||||
|
||||
func (ntg NTGVision) searchJobReadCloser(id int64) (io.ReadCloser, error) {
|
||||
func (ntg NTGVision) searchJob(id int64) (io.ReadCloser, error) {
|
||||
time.Sleep(config.Get().Interval.JobInfo.Get())
|
||||
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf(config.Get().Brokers.NTG.LoadPageAPIURIFormat, id), nil)
|
||||
if err != nil {
|
||||
|
|
@ -170,8 +169,8 @@ func (ntg NTGVision) WithMock() NTGVision {
|
|||
return ntg
|
||||
}
|
||||
|
||||
func (ntg NTGVision) searchJob(id int64) (ntgVisionJobInfo, error) {
|
||||
rc, err := ntg.searcher.searchJobReadCloser(id)
|
||||
func (ntg NTGVision) SearchJob(id int64) (ntgVisionJobInfo, error) {
|
||||
rc, err := ntg.searcher.searchJob(id)
|
||||
if err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
|
|
@ -188,77 +187,8 @@ func (ntg NTGVision) searchJob(id int64) (ntgVisionJobInfo, error) {
|
|||
return result, err
|
||||
}
|
||||
|
||||
func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
|
||||
radius := config.Get().Brokers.RadiusMiles
|
||||
statesm := map[string]struct{}{}
|
||||
for _, z := range zips {
|
||||
somestates := zip.GetStatesWithin(zip.Get(z), radius)
|
||||
for _, state := range somestates {
|
||||
statesm[state] = struct{}{}
|
||||
}
|
||||
}
|
||||
states := make([]config.State, 0, len(statesm))
|
||||
for state := range statesm {
|
||||
states = append(states, config.State(state))
|
||||
}
|
||||
if len(states) == 0 {
|
||||
return nil, fmt.Errorf("failed to map zipcodes %+v to any states", zips)
|
||||
}
|
||||
jobs, err := ntg.SearchStates(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := len(jobs) - 1; i >= 0; i-- {
|
||||
ok := false
|
||||
for _, z := range zips {
|
||||
ok = ok || zip.Get(z).MilesTo(zip.FromCityState(jobs[i].Pickup.City, jobs[i].Pickup.State)) <= radius
|
||||
}
|
||||
if !ok {
|
||||
jobs[i], jobs[len(jobs)-1] = jobs[len(jobs)-1], jobs[i]
|
||||
jobs = jobs[:len(jobs)-1]
|
||||
}
|
||||
}
|
||||
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))
|
||||
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 {
|
||||
return false
|
||||
}
|
||||
if ok := func() bool {
|
||||
for _, weekday := range working.Weekdays {
|
||||
if now.Weekday() == time.Weekday(weekday) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}(); !ok {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
rc, err := ntg.searcher.searchStates(states)
|
||||
func (ntg NTGVision) Search(states []config.State) ([]Job, error) {
|
||||
rc, err := ntg.searcher.search(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -273,22 +203,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 {
|
||||
|
|
@ -306,20 +226,20 @@ func setNTGToken(token string) {
|
|||
db.Set(getNTGTokenKey(), []byte(token))
|
||||
}
|
||||
|
||||
func (ntg NTGVision) searchStates(states []config.State) (io.ReadCloser, error) {
|
||||
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
||||
if getNTGToken() == "" {
|
||||
logtr.Debugf("NTG token is empty, refreshing ntg auth")
|
||||
if err := ntg.refreshAuth(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
rc, err := ntg._searchStates(states)
|
||||
rc, err := ntg._search(states)
|
||||
if err == ErrNoAuth {
|
||||
logtr.Debugf("err no auth on search, refreshing ntg auth")
|
||||
if err := ntg.refreshAuth(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc, err = ntg._searchStates(states)
|
||||
rc, err = ntg._search(states)
|
||||
}
|
||||
return rc, err
|
||||
}
|
||||
|
|
@ -365,7 +285,7 @@ func (ntg NTGVision) _refreshAuth() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ntg NTGVision) _searchStates(states []config.State) (io.ReadCloser, error) {
|
||||
func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
|
||||
request, err := ntg.newRequest(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -374,16 +294,13 @@ func (ntg NTGVision) _searchStates(states []config.State) (io.ReadCloser, error)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
resp.Body = io.NopCloser(bytes.NewReader(b))
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
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 || resp.StatusCode == 417 { // TODO wtf is 417 for
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 404 {
|
||||
logtr.Debugf("ntg auth bad status: err no auth")
|
||||
return nil, ErrNoAuth
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"local/truckstop/config"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
|
@ -15,13 +15,13 @@ func NewNTGVisionMock() NTGVisionMock {
|
|||
return NTGVisionMock{}
|
||||
}
|
||||
|
||||
func (ntgm NTGVisionMock) searchStates(states []config.State) (io.ReadCloser, error) {
|
||||
func (ntgm NTGVisionMock) search(states []config.State) (io.ReadCloser, error) {
|
||||
path := path.Join(os.Getenv("GOPATH"), "src", "local", "truckstop", "broker", "testdata", "ntgvision_response.json")
|
||||
b, err := ioutil.ReadFile(path)
|
||||
return io.NopCloser(bytes.NewReader(b)), err
|
||||
}
|
||||
|
||||
func (ntgm NTGVisionMock) searchJobReadCloser(id int64) (io.ReadCloser, error) {
|
||||
func (ntgm NTGVisionMock) searchJob(id int64) (io.ReadCloser, error) {
|
||||
path := path.Join(os.Getenv("GOPATH"), "src", "local", "truckstop", "broker", "testdata", "ntgvision_jobinfo_response.json")
|
||||
b, err := ioutil.ReadFile(path)
|
||||
return io.NopCloser(bytes.NewReader(b)), err
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
package broker
|
||||
|
||||
import (
|
||||
"gogs.inhome.blapointe.com/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")
|
||||
}
|
||||
if ntg.workingHours(time.Date(2022, 1, 27, 23, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
||||
t.Fatal("midnight MST ok")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#! /bin/bash
|
||||
|
||||
curl -i -Ss \
|
||||
'https://www.fastexact.com/secure/index.php?page=userLogin' \
|
||||
-X POST \
|
||||
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' \
|
||||
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
|
||||
-H 'Accept-Language: en-US,en;q=0.5' \
|
||||
-H 'Accept-Encoding: gzip, deflate, br' \
|
||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||
--data-raw 'user_name=birdman&user_password=166647&buttonSubmit=Login' \
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#! /bin/bash
|
||||
curl -sS \
|
||||
'https://www.fastexact.com/secure/index.php?page=ajaxListJobs&action=ajax&zipcode=27006&records_per_page=10&distance=300&st_loc_zip=8' \
|
||||
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' \
|
||||
-H 'Accept: */*' \
|
||||
-H 'Accept-Language: en-US,en;q=0.5' \
|
||||
-H 'Accept-Encoding: gzip, deflate, br' \
|
||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||
-H 'Cookie: PHPSESSID=vq4ss3lbfg0viluaau7e0d32q6' \
|
||||
| gzip -d
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
<form name="frm_search" action="index.php?page=manageJobs" method="post">
|
||||
<a href="https://play.google.com/store/apps/details?id=app.FastExact" target="_blank" title="Android app, Available in the App Store, Download and get all more..." class="android_app"></a>
|
||||
<a href="http://itunes.apple.com/us/app/fastexact/id497933887?mt=8" target="_blank" title="iPhone app, Available in the App Store, Download and get all more..." class="iphone_app"></a>
|
||||
<div class="search_box w67p">
|
||||
<div class="header"><strong>Search</strong> <span class="usZipLink"><a href="http://zip4.usps.com/zip4/citytown.jsp" title="US Zip Code Finder" target="_blank">US Zip Code Finder »</a></span> </div>
|
||||
<div class="content">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td valign="top" width="342"><strong>Enter your Zip Code to show radius
|
||||
<!--of 100 miles-->
|
||||
from your location</strong></td>
|
||||
<td valign="top" width="68"><input type="text" name="zipcode" id="zipcode" value="27006" onKeyPress="return disableEnterKey(event)" onkeydown="if(event.keyCode == 13){radiusSearch('10')}" /></td>
|
||||
<td valign="top" width="59"><select name="distance" id="distance" class="select" onkeydown="if(event.keyCode == 13){radiusSearch('10')}">
|
||||
<option value="100" >100</option>
|
||||
<option value="200" >200</option>
|
||||
<option value="300" selected=selected>300</option>
|
||||
</select></td>
|
||||
<td valign="top" width="128"><!--<input type="checkbox" name="st_loc_zip" id="st_loc_zip" value="1" class="ownBox" checked=checked onKeyPress="return disableEnterKey(event)" onkeydown="if(event.keyCode == 13){radiusSearch('10')}"/>--></td>
|
||||
<td valign="top" class="padr12" width="337">Make this your current zip code<br />
|
||||
for the next
|
||||
<select name="st_loc_zip" id="st_loc_zip" class="dropdown">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
<option value="5">5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8" selected="selected">8</option>
|
||||
<option value="9">9</option>
|
||||
<option value="10">10</option>
|
||||
<option value="11">11</option>
|
||||
<option value="12">12</option>
|
||||
<option value="13">13</option>
|
||||
<option value="14">14</option>
|
||||
<option value="15">15</option>
|
||||
<option value="16">16</option>
|
||||
<option value="17">17</option>
|
||||
<option value="18">18</option>
|
||||
<option value="19">19</option>
|
||||
<option value="20">20</option>
|
||||
<option value="21">21</option>
|
||||
<option value="22">22</option>
|
||||
<option value="23">23</option>
|
||||
<option value="24">24</option>
|
||||
</select>
|
||||
hours.<a href="javascript:radiusSearch('10','save');" ><img src="images/buttons/save.png" /></a></td>
|
||||
<td valign="top"><a href="javascript:radiusSearch('10','search');"><img src="images/buttons/search.gif" alt="Search" align="middle" title="Search" /></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="br"></div>
|
||||
</form>
|
||||
<br clear="all" />
|
||||
<div id="list" align="center">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="Order List">
|
||||
<tr>
|
||||
<th width="14%" height="38" align="center">ID <span id="sort8"><a href="javascript:contentSort('ordernum=8&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',8)"> <img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0" /></a></span></th>
|
||||
<th width="14%" height="38" align="center">Origin <span id="sort1"><a href="javascript:contentSort('ordernum=1&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',1)"> <img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0" /></a></span></th>
|
||||
<th width="14%" height="38" align="center">Destination <span id="sort2"><a href="javascript:contentSort('ordernum=2&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',2)"> <img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0" /></a></span></th>
|
||||
<th width="14%" height="38" align="center">Mile <span id="sort3"><a href="javascript:contentSort('ordernum=3&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',3)"> <img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0" /></a></span></th>
|
||||
<th height="38" align="center">Pieces / Weight <span id="sort4"><a href="javascript:contentSort('ordernum=4&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',4)"> <img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0"/></a></span></th>
|
||||
<th width="14%" height="38" align="center">Dimension <span id="sort5"><a href="javascript:contentSort('ordernum=5&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',5)"><img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0"/></a></span></th>
|
||||
<th width="14%" height="38" align="center">Vehicle Size <span id="sort5"><a href="javascript:contentSort('ordernum=5&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',5)"><img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0"/></a></span></th>
|
||||
<th width="20%" height="38" align="center">Pickup (EST) <span id="sort6"><a href="javascript:contentSort('ordernum=6&dir=asc&pageNum=1&zipcode=27006&distance=300&st_loc_zip=8&records_per_page=10',6)"> <img src="https://www.fastexact.com/secure/images/sortarrow_down.gif" border="0" /></a></span></th>
|
||||
<th width="6%" height="38" align="center">View</th>
|
||||
</tr>
|
||||
<tr >
|
||||
<td align="center" height="38">Z-5344222</td>
|
||||
<td align="center" height="38">Circleville, OH 43113</td>
|
||||
<td align="center">Willard, OH 44890</td>
|
||||
<td align="center">128</td>
|
||||
<td align="center">4 / 4800</td>
|
||||
<td align="center">96x48x88in.</td>
|
||||
<td align="center">SMALL STRAIGHT</td>
|
||||
<td align="center">31-Jan-2022 17:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344222"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr class="alternate">
|
||||
<td align="center" height="38">Z-5344003</td>
|
||||
<td align="center" height="38">WASHINGTON, DC</td>
|
||||
<td align="center">WINSTON SALEM, NC</td>
|
||||
<td align="center">332</td>
|
||||
<td align="center">2 / 3000</td>
|
||||
<td align="center">78x35x99 in.</td>
|
||||
<td align="center">LARGE STRAIGHT</td>
|
||||
<td align="center">31-Jan-2022 08:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344003"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td align="center" height="38">Z-5344092</td>
|
||||
<td align="center" height="38">Winchester, VA 22603</td>
|
||||
<td align="center">Milwaukee, WI 53221</td>
|
||||
<td align="center">728</td>
|
||||
<td align="center">4 / 2195</td>
|
||||
<td align="center">NO DIMENSIONS SPECIFIED</td>
|
||||
<td align="center">VAN</td>
|
||||
<td align="center">30-Jan-2022 15:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344092"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr class="alternate">
|
||||
<td align="center" height="38">Z-5344035</td>
|
||||
<td align="center" height="38">ATLANTA, GA 30301</td>
|
||||
<td align="center">BURNSVILLE, MN 55337</td>
|
||||
<td align="center">1098</td>
|
||||
<td align="center">10 / 6000</td>
|
||||
<td align="center">48x40x40 in.</td>
|
||||
<td align="center">LARGE STRAIGHT</td>
|
||||
<td align="center">29-Jan-2022 08:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344035"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td align="center" height="38">Z-5344518</td>
|
||||
<td align="center" height="38">Hamlet, NC 28345</td>
|
||||
<td align="center">East Windsor, CT 06088</td>
|
||||
<td align="center">720</td>
|
||||
<td align="center">1 / 500</td>
|
||||
<td align="center">54x36x24in.</td>
|
||||
<td align="center">CARGO VAN</td>
|
||||
<td align="center">28-Jan-2022 13:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344518"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr class="alternate">
|
||||
<td align="center" height="38">X-5344304</td>
|
||||
<td align="center" height="38">MOUNT PLEASANT, PA 15666</td>
|
||||
<td align="center">MIAMI, FL 33178-1056</td>
|
||||
<td align="center">1156</td>
|
||||
<td align="center">0 / 5000.00</td>
|
||||
<td align="center">48Inches x 48Inches x </td>
|
||||
<td align="center">Straight Truck 20-24 ft</td>
|
||||
<td align="center">28-Jan-2022 13:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344304"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td align="center" height="38">Z-5344061</td>
|
||||
<td align="center" height="38">Chesapeake, VA 23321</td>
|
||||
<td align="center">Fort Wayne, IN 46818</td>
|
||||
<td align="center">727</td>
|
||||
<td align="center">0 / 5000</td>
|
||||
<td align="center">NO DIMENSIONS SPECIFIED</td>
|
||||
<td align="center">LARGE STRAIGHT</td>
|
||||
<td align="center">28-Jan-2022 13:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344061"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr class="alternate">
|
||||
<td align="center" height="38">B-5344514</td>
|
||||
<td align="center" height="38">MAXTON, NC 28364</td>
|
||||
<td align="center">PEMBINA, ND 58271</td>
|
||||
<td align="center">1637</td>
|
||||
<td align="center">7 / 28000</td>
|
||||
<td align="center">7@54x96x40</td>
|
||||
<td align="center"></td>
|
||||
<td align="center">28-Jan-2022 12:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344514"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td align="center" height="38">Z-5344114</td>
|
||||
<td align="center" height="38">Durham, NC 27703</td>
|
||||
<td align="center">Cumming, GA 30040</td>
|
||||
<td align="center">368</td>
|
||||
<td align="center">6 / 3200</td>
|
||||
<td align="center">48x40x48in.</td>
|
||||
<td align="center">LARGE STRAIGHT</td>
|
||||
<td align="center">28-Jan-2022 12:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344114"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
<tr class="alternate">
|
||||
<td align="center" height="38">Z-5344231</td>
|
||||
<td align="center" height="38">Durham, NC 27702</td>
|
||||
<td align="center">Cumming, GA 30040</td>
|
||||
<td align="center">366</td>
|
||||
<td align="center">6 / 3200</td>
|
||||
<td align="center">48x40x48in.</td>
|
||||
<td align="center">LARGE STRAIGHT</td>
|
||||
<td align="center">28-Jan-2022 12:00:00</td>
|
||||
<td align="center"><!--thickbox-->
|
||||
<a title="Do Bidding" href="https://www.fastexact.com/secure/index.php?page=doBidding&job_id=5344231"><img src="https://www.fastexact.com/site_manager/images/icons/view.jpg" border="0" title="View this Record" /></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<br clear="all" />
|
||||
<div class="paging">
|
||||
<table cellspacing="0" cellpadding="0" border="0" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Details Found: 81<img height="1" width="14" alt="" src="images/tspacer.gif">Page 1 of 9</td>
|
||||
<td align="center"><div id="Page">
|
||||
<img height="1" width="8" alt="" src="images/tspacer.gif">
|
||||
<a href="javascript:fnPaging('pageNum=2&records_per_page=10&zipcode=27006&distance=300&st_loc_zip=8')">Next</a> <strong>»</strong>
|
||||
</div></td>
|
||||
<td align="right"><table cellspacing="0" cellpadding="0" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top" class="record">Records Per Page: </td>
|
||||
<td valign="top"><div id="recNum">
|
||||
<select style="font-size: 11px;" class="dropdown" id="pagei" name="pagei" onchange="changeRecordCount('27006','300','8')">
|
||||
<option value="10" selected="selected" >10</option>
|
||||
<option value="20" >20</option>
|
||||
<option value="50" >50</option>
|
||||
<option value="100" >100</option>
|
||||
</select>
|
||||
</div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
26
config.json
26
config.json
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Log": {
|
||||
"Path": "/tmp/truckstop.log",
|
||||
"Level": "DEB",
|
||||
"Level": "debug",
|
||||
"SOSMatrix": {
|
||||
"ReceiveEnabled": true,
|
||||
"Mock": false,
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
"Pickup": false,
|
||||
"Dropoff": false,
|
||||
"Pathed": {
|
||||
"Enabled": false,
|
||||
"Enabled": true,
|
||||
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
||||
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s",
|
||||
"Zoom": {
|
||||
|
|
@ -48,11 +48,6 @@
|
|||
"States": [
|
||||
"NC"
|
||||
],
|
||||
"Zips": [
|
||||
"27006",
|
||||
"73044",
|
||||
"84058"
|
||||
],
|
||||
"IDs": {
|
||||
"Matrix": "@bel:m.bltrucks.top"
|
||||
},
|
||||
|
|
@ -74,28 +69,15 @@
|
|||
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
|
||||
}
|
||||
},
|
||||
"Once": false,
|
||||
"Once": true,
|
||||
"Brokers": {
|
||||
"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,
|
||||
"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",
|
||||
"Password": "thumper12345"
|
||||
},
|
||||
"FastExact": {
|
||||
"Enabled": true,
|
||||
"Mock": true,
|
||||
"Username": "birdman",
|
||||
"Password": "166647"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,6 @@
|
|||
"States": [
|
||||
"NC"
|
||||
],
|
||||
"Zips": [
|
||||
"27006"
|
||||
],
|
||||
"IDs": {
|
||||
"Matrix": "@bel:m.bltrucks.top"
|
||||
},
|
||||
|
|
@ -74,24 +71,11 @@
|
|||
},
|
||||
"Once": true,
|
||||
"Brokers": {
|
||||
"UseZips": true,
|
||||
"RadiusMiles": 100,
|
||||
"FastExact": {
|
||||
"Enabled": true,
|
||||
"Mock": true,
|
||||
"Username": "u",
|
||||
"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,
|
||||
"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",
|
||||
"Password": "thumper1234"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package config
|
|||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/storage"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"local/storage"
|
||||
"local/truckstop/logtr"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -64,14 +64,7 @@ type Config struct {
|
|||
}
|
||||
Once bool
|
||||
Brokers struct {
|
||||
UseZips bool
|
||||
RadiusMiles int
|
||||
NTG struct {
|
||||
Working struct {
|
||||
Hours []int
|
||||
Weekdays []int
|
||||
}
|
||||
Enabled bool
|
||||
NTG struct {
|
||||
JobInfo bool
|
||||
Mock bool
|
||||
LoadPageURIFormat string
|
||||
|
|
@ -80,7 +73,6 @@ type Config struct {
|
|||
Password string
|
||||
}
|
||||
FastExact struct {
|
||||
Enabled bool
|
||||
Mock bool
|
||||
Username string
|
||||
Password string
|
||||
|
|
@ -93,7 +85,6 @@ type Config struct {
|
|||
|
||||
type Client struct {
|
||||
States []State
|
||||
Zips []string
|
||||
IDs struct {
|
||||
Matrix string
|
||||
}
|
||||
|
|
@ -121,20 +112,6 @@ func Clients(t time.Time) map[string]Client {
|
|||
return result
|
||||
}
|
||||
|
||||
func AllZips() []string {
|
||||
zipm := map[string]struct{}{}
|
||||
for _, v := range Clients(time.Now().Add(time.Hour * 24 * 365)) {
|
||||
for _, state := range v.Zips {
|
||||
zipm[state] = struct{}{}
|
||||
}
|
||||
}
|
||||
zips := make([]string, 0, len(zipm)+1)
|
||||
for k := range zipm {
|
||||
zips = append(zips, k)
|
||||
}
|
||||
return zips
|
||||
}
|
||||
|
||||
func AllStates() []State {
|
||||
statem := map[State]struct{}{}
|
||||
for _, v := range Clients(time.Now().Add(time.Hour * 24 * 365)) {
|
||||
|
|
|
|||
27
go.mod
27
go.mod
|
|
@ -1,26 +1,36 @@
|
|||
module gogs.inhome.blapointe.com/local/truckstop
|
||||
module local/truckstop
|
||||
|
||||
go 1.17
|
||||
|
||||
replace local/storage => ../storage
|
||||
|
||||
replace local/logb => ../logb
|
||||
|
||||
replace local/sandbox/contact/contact => ../sandbox/contact/contact
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.8.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
|
||||
gogs.inhome.blapointe.com/local/storage v0.0.0-20230410162102-db39d7b02e29
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
|
||||
local/sandbox/contact/contact v0.0.0-00010101000000-000000000000
|
||||
local/storage v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.33.1 // indirect
|
||||
github.com/Unknwon/goconfig v0.0.0-20181105214110-56bd8ab18619 // indirect
|
||||
github.com/abbot/go-http-auth v0.4.0 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.1 // indirect
|
||||
github.com/aws/aws-sdk-go v1.15.81 // indirect
|
||||
github.com/boltdb/bolt v1.3.1 // indirect
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
|
||||
github.com/buraksezer/consistent v0.9.0 // indirect
|
||||
github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e // indirect
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
github.com/emersion/go-imap v1.2.0 // indirect
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/golang/protobuf v1.2.0 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/gomodule/redigo v1.8.5 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||
github.com/json-iterator/go v1.1.9 // indirect
|
||||
github.com/klauspost/compress v1.9.5 // indirect
|
||||
|
|
@ -45,16 +55,17 @@ require (
|
|||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.mongodb.org/mongo-driver v1.7.2 // indirect
|
||||
gogs.inhome.blapointe.com/local/logb v0.0.0-20230410154319-880efa39d871 // indirect
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
|
||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20181120190819-8f65e3013eba // indirect
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect
|
||||
google.golang.org/api v0.0.0-20181120235003-faade3cbb06a // indirect
|
||||
google.golang.org/appengine v1.3.0 // indirect
|
||||
gopkg.in/ini.v1 v1.42.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
local/logb v0.0.0-00010101000000-000000000000 // indirect
|
||||
)
|
||||
|
|
|
|||
30
go.sum
30
go.sum
|
|
@ -5,21 +5,27 @@ github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9a
|
|||
github.com/Azure/azure-storage-blob-go v0.0.0-20181023070848-cf01652132cc/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/Unknwon/goconfig v0.0.0-20181105214110-56bd8ab18619 h1:6X8iB881g299aNEv6KXrcjL31iLOH7yA6NXoQX+MbDg=
|
||||
github.com/Unknwon/goconfig v0.0.0-20181105214110-56bd8ab18619/go.mod h1:wngxua9XCNjvHjDiTiV26DaKDT+0c63QR6H5hjVUUxw=
|
||||
github.com/a8m/tree v0.0.0-20180321023834-3cf936ce15d6/go.mod h1:FSdwKX97koS5efgm8WevNf7XS3PqtyFkKDDXrz778cg=
|
||||
github.com/abbot/go-http-auth v0.4.0 h1:QjmvZ5gSC7jm3Zg54DqWE/T5m1t2AfDu6QlXJT0EVT0=
|
||||
github.com/abbot/go-http-auth v0.4.0/go.mod h1:Cz6ARTIzApMJDzh5bRMSUou6UMSp0IEXg9km/ci7TJM=
|
||||
github.com/anacrolix/dms v0.0.0-20180117034613-8af4925bffb5/go.mod h1:DGqLjaZ3ziKKNRt+U5Q9PLWJ52Q/4rxfaaH/b3QYKaE=
|
||||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
github.com/aws/aws-sdk-go v1.15.81 h1:va7uoFaV9uKAtZ6BTmp1u7paoMsizYRRLvRuoC07nQ8=
|
||||
github.com/aws/aws-sdk-go v1.15.81/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
|
||||
github.com/billziss-gh/cgofuse v1.1.0/go.mod h1:LJjoaUojlVjgo5GQoEJTcJNqZJeRU0nCR84CyxKt2YM=
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||
github.com/buraksezer/consistent v0.9.0 h1:Zfs6bX62wbP3QlbPGKUhqDw7SmNkOzY5bHZIYXYpR5g=
|
||||
github.com/buraksezer/consistent v0.9.0/go.mod h1:6BrVajWq7wbKZlTOUPs/XVfR8c0maujuPowduSpZqmw=
|
||||
github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e h1:mQTN05gz0rDZSABqKMzAPMb5ATWcvvdMljRzEh0LjBo=
|
||||
github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e/go.mod h1:alXX+s7a4cKaIprgjeEboqi4Tm7XR/HXEwUTxUV/ywU=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/coreos/bbolt v0.0.0-20180318001526-af9db2027c98/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||
github.com/cpuguy83/go-md2man v1.0.8/go.mod h1:N6JayAiVKtlHSnuTCeuLSQVs75hb8q+dYQLjr7cDsKY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
|
@ -28,6 +34,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||
github.com/djherbis/times v1.1.0/go.mod h1:CGMZlo255K5r4Yw0b9RRfFQpM2y7uOmxg4jm9HsaVf8=
|
||||
github.com/dropbox/dropbox-sdk-go-unofficial v5.4.0+incompatible/go.mod h1:lr+LhMM3F6Y3lW1T9j2U5l7QeuWm87N9+PPXo3yH4qY=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/emersion/go-imap v1.2.0 h1:lyUQ3+EVM21/qbWE/4Ya5UG9r5+usDxlg4yfp3TgHFA=
|
||||
github.com/emersion/go-imap v1.2.0/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY=
|
||||
github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4=
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ=
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
|
||||
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
|
|
@ -162,6 +174,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1
|
|||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
|
|
@ -191,10 +205,6 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
|
|||
github.com/yunify/qingstor-sdk-go v2.2.15+incompatible/go.mod h1:w6wqLDQ5bBTzxGJ55581UrSwLrsTAsdo9N6yX/8d9RY=
|
||||
go.mongodb.org/mongo-driver v1.7.2 h1:pFttQyIiJUHEn50YfZgC9ECjITMT44oiN36uArf/OFg=
|
||||
go.mongodb.org/mongo-driver v1.7.2/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8=
|
||||
gogs.inhome.blapointe.com/local/logb v0.0.0-20230410154319-880efa39d871 h1:cMGPiwvK/QGg4TfW8VasO6SsS/O7UQmwyKDErV/ozoA=
|
||||
gogs.inhome.blapointe.com/local/logb v0.0.0-20230410154319-880efa39d871/go.mod h1:E0pLNvMLzY0Kth1W078y+06z1AUyVMWnChMpRFf4w2Q=
|
||||
gogs.inhome.blapointe.com/local/storage v0.0.0-20230410162102-db39d7b02e29 h1:SPSz7yQsEfScqyLlBS5uNSOGeT203BkIkFCL8jrm/FA=
|
||||
gogs.inhome.blapointe.com/local/storage v0.0.0-20230410162102-db39d7b02e29/go.mod h1:zk8Fe2Ezc2f6oOe2yllsbEhXqssUU1K2faoS0eQ9alY=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
|
@ -209,7 +219,6 @@ golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73r
|
|||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
|
||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
|
|
@ -233,9 +242,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
|
|||
224
main.go
224
main.go
|
|
@ -4,23 +4,21 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gogs.inhome.blapointe.com/local/storage"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/broker"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/message"
|
||||
"local/storage"
|
||||
"local/truckstop/broker"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
"local/truckstop/message"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var stateFinder = regexp.MustCompile(`[A-Za-z]+`)
|
||||
var zipFinder = regexp.MustCompile(`[0-9]{5}[0-9]*`)
|
||||
|
||||
func main() {
|
||||
if err := _main(); err != nil {
|
||||
|
|
@ -64,15 +62,15 @@ func _main() error {
|
|||
}
|
||||
|
||||
func matrixrecv() error {
|
||||
logtr.Verbosef("checking matrix...")
|
||||
defer logtr.Verbosef("/checking matrix...")
|
||||
logtr.Debugf("checking matrix...")
|
||||
defer logtr.Debugf("/checking matrix...")
|
||||
sender := message.NewMatrix()
|
||||
messages, err := sender.Receive()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func() {
|
||||
logtr.Verbosef("looking for help")
|
||||
logtr.Debugf("looking for help")
|
||||
printed := false
|
||||
for _, msg := range messages {
|
||||
if !strings.HasPrefix(msg.Content, "!help") {
|
||||
|
|
@ -83,11 +81,7 @@ func matrixrecv() error {
|
|||
if !printed {
|
||||
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||
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\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...`!state nc NC nC Nc` set states for self\n...`!available 2022-12-31` set date self is available for work\n\nrun a command for someone else: `!state ga @caleb`")
|
||||
if err := sender.Send(help); err != nil {
|
||||
logtr.Errorf("failed to send help: %v", err)
|
||||
} else {
|
||||
|
|
@ -105,33 +99,7 @@ func matrixrecv() error {
|
|||
}
|
||||
}()
|
||||
func() {
|
||||
logtr.Verbosef("looking for zips")
|
||||
db := config.Get().DB()
|
||||
zips := map[string]map[string]struct{}{}
|
||||
for _, msg := range messages {
|
||||
key := fmt.Sprintf("zips_%d", msg.Timestamp.Unix())
|
||||
if !strings.HasPrefix(msg.Content, "!zip") {
|
||||
continue
|
||||
}
|
||||
if _, ok := zips[msg.Sender]; ok {
|
||||
continue
|
||||
}
|
||||
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||
zips[msg.Sender] = map[string]struct{}{}
|
||||
for _, zip := range parseOutZips([]byte(msg.Content)) {
|
||||
zips[msg.Sender][zip] = struct{}{}
|
||||
}
|
||||
}
|
||||
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||
logtr.Errorf("failed to mark state gathered @%s: %v", key, err)
|
||||
}
|
||||
}
|
||||
if config.Get().Brokers.UseZips {
|
||||
setNewZips(zips)
|
||||
}
|
||||
}()
|
||||
func() {
|
||||
logtr.Verbosef("looking for states")
|
||||
logtr.Debugf("looking for states")
|
||||
db := config.Get().DB()
|
||||
states := map[string]map[config.State]struct{}{}
|
||||
for _, msg := range messages {
|
||||
|
|
@ -152,37 +120,10 @@ func matrixrecv() error {
|
|||
logtr.Errorf("failed to mark state gathered @%s: %v", key, err)
|
||||
}
|
||||
}
|
||||
if !config.Get().Brokers.UseZips {
|
||||
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() {
|
||||
logtr.Verbosef("looking for pauses")
|
||||
logtr.Debugf("looking for pauses")
|
||||
db := config.Get().DB()
|
||||
pauses := map[string]time.Time{}
|
||||
for _, msg := range messages {
|
||||
|
|
@ -204,7 +145,7 @@ func matrixrecv() error {
|
|||
}
|
||||
}
|
||||
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||
logtr.Errorf("failed to mark pause gathered @%s: %v", key, err)
|
||||
logtr.Errorf("failed to mark state gathered @%s: %v", key, err)
|
||||
}
|
||||
}
|
||||
setNewPauses(pauses)
|
||||
|
|
@ -213,33 +154,6 @@ 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
|
||||
|
|
@ -268,41 +182,6 @@ func setNewPauses(pauses map[string]time.Time) {
|
|||
}
|
||||
}
|
||||
|
||||
func setNewZips(zips map[string]map[string]struct{}) {
|
||||
if len(zips) == 0 {
|
||||
return
|
||||
}
|
||||
conf := *config.Get()
|
||||
changed := map[string][]string{}
|
||||
for client, clientZips := range zips {
|
||||
newzips := []string{}
|
||||
for k := range clientZips {
|
||||
newzips = append(newzips, k)
|
||||
}
|
||||
sort.Slice(newzips, func(i, j int) bool {
|
||||
return newzips[i] < newzips[j]
|
||||
})
|
||||
clientconf := conf.Clients[client]
|
||||
if fmt.Sprint(newzips) == fmt.Sprint(clientconf.Zips) {
|
||||
message.NewMatrix().Send(fmt.Sprintf("%s: still searching for %+v", client, newzips))
|
||||
continue
|
||||
}
|
||||
clientconf.Zips = newzips
|
||||
conf.Clients[client] = clientconf
|
||||
changed[client] = newzips
|
||||
}
|
||||
if len(changed) == 0 {
|
||||
return
|
||||
}
|
||||
logtr.Infof("updating config new zips: %+v", conf)
|
||||
config.Set(conf)
|
||||
for client, zips := range changed {
|
||||
if err := sendNewZips(client, zips); err != nil {
|
||||
logtr.Errorf("failed to send new zips %s/%+v: %v", client, zips, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setNewStates(states map[string]map[config.State]struct{}) {
|
||||
if len(states) == 0 {
|
||||
return
|
||||
|
|
@ -338,18 +217,6 @@ func setNewStates(states map[string]map[config.State]struct{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func parseOutZips(b []byte) []string {
|
||||
var zips []string
|
||||
candidates := zipFinder.FindAll(b, -1)
|
||||
for _, candidate := range candidates {
|
||||
if len(candidate) != 5 {
|
||||
continue
|
||||
}
|
||||
zips = append(zips, string(candidate))
|
||||
}
|
||||
return zips
|
||||
}
|
||||
|
||||
func parseOutStates(b []byte) []config.State {
|
||||
var states []config.State
|
||||
var state config.State
|
||||
|
|
@ -375,7 +242,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 {
|
||||
|
|
@ -436,7 +303,7 @@ func once() error {
|
|||
if ok, err := sendJob(jobs[i]); err != nil {
|
||||
return err
|
||||
} else if ok {
|
||||
logtr.Debugf("sent job %+v", jobs[i])
|
||||
logtr.Debugf("sent job", jobs[i])
|
||||
if err := db.Set(jobs[i].UID(), []byte(`sent`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -446,30 +313,12 @@ func once() error {
|
|||
}
|
||||
|
||||
func getJobs() ([]broker.Job, error) {
|
||||
if config.Get().Brokers.UseZips {
|
||||
return getJobsZips()
|
||||
}
|
||||
return getJobsStates()
|
||||
}
|
||||
|
||||
func getJobsZips() ([]broker.Job, error) {
|
||||
zips := config.AllZips()
|
||||
jobs := []broker.Job{}
|
||||
for _, broker := range getBrokers() {
|
||||
somejobs, err := broker.SearchZips(zips)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jobs = append(jobs, somejobs...)
|
||||
}
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func getJobsStates() ([]broker.Job, error) {
|
||||
states := config.AllStates()
|
||||
ntg := broker.NewNTGVision()
|
||||
brokers := []broker.Broker{ntg}
|
||||
jobs := []broker.Job{}
|
||||
for _, broker := range getBrokers() {
|
||||
somejobs, err := broker.SearchStates(states)
|
||||
for _, broker := range brokers {
|
||||
somejobs, err := broker.Search(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -478,19 +327,6 @@ func getJobsStates() ([]broker.Job, error) {
|
|||
return jobs, nil
|
||||
}
|
||||
|
||||
func getBrokers() []broker.Broker {
|
||||
brokers := []broker.Broker{}
|
||||
if config.Get().Brokers.NTG.Enabled {
|
||||
logtr.Debugf("NTG enabled")
|
||||
brokers = append(brokers, broker.NewNTGVision())
|
||||
}
|
||||
if config.Get().Brokers.FastExact.Enabled {
|
||||
logtr.Debugf("FastExact enabled")
|
||||
brokers = append(brokers, broker.NewFastExact())
|
||||
}
|
||||
return brokers
|
||||
}
|
||||
|
||||
type recordedJob struct {
|
||||
Job broker.Job
|
||||
SentNS int64
|
||||
|
|
@ -508,7 +344,7 @@ func updateDeadJobs(jobs []broker.Job) error {
|
|||
wouldBe := strings.TrimPrefix(listEntry, "sent_job_")
|
||||
found := false
|
||||
for i := range jobs {
|
||||
found = found || jobs[i].UID() == wouldBe || jobs[i].ID == wouldBe
|
||||
found = found || jobs[i].ID == wouldBe
|
||||
}
|
||||
logtr.Debugf("found job %s to be still alive==%v", wouldBe, found)
|
||||
if !found {
|
||||
|
|
@ -526,12 +362,15 @@ func updateDeadJobs(jobs []broker.Job) error {
|
|||
return err
|
||||
}
|
||||
*/
|
||||
if err := message.NewMatrix().Remove(recorded.MatrixID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := db.Set(listEntry, nil); err != nil {
|
||||
logtr.Debugf("failed to remove db: %v: %v", listEntry, err)
|
||||
return err
|
||||
}
|
||||
for _, imageid := range recorded.MatrixImageIDs {
|
||||
if err := message.NewMatrix().Update(imageid, "<job no longer available>"); err != nil {
|
||||
logtr.Debugf("failed to update matrix image: %v: %v", imageid, err)
|
||||
if err := message.NewMatrix().Remove(imageid); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -560,7 +399,7 @@ func dropBanlistJobs(jobs []broker.Job) ([]broker.Job, error) {
|
|||
func sendJob(job broker.Job) (bool, error) {
|
||||
sender := message.NewMatrix()
|
||||
payload := job.FormatMultilineText()
|
||||
logtr.Debugf("once: send job %s if nonzero: %q", job.String(), payload)
|
||||
logtr.Debugf("once: send job %s if nonzero: %s", job.String(), payload)
|
||||
if len(payload) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
|
@ -580,7 +419,7 @@ func sendJob(job broker.Job) (bool, error) {
|
|||
logtr.Errorf("failed to marshal recorded job: %v", err)
|
||||
return
|
||||
}
|
||||
if err := db.Set("sent_job_"+job.UID(), b); err != nil {
|
||||
if err := db.Set("sent_job_"+job.ID, b); err != nil {
|
||||
logtr.Errorf("failed to set recorded job: %v", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -670,14 +509,9 @@ func sendJob(job broker.Job) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func sendNewZips(client string, zips []string) error {
|
||||
sender := message.NewMatrix()
|
||||
return sender.Send(fmt.Sprintf("%s: now searching for loads from zip codes: %+v", client, zips))
|
||||
}
|
||||
|
||||
func sendNewStates(client string, states []config.State) error {
|
||||
sender := message.NewMatrix()
|
||||
return sender.Send(fmt.Sprintf("%s: now searching for loads from states: %+v", client, states))
|
||||
return sender.Send(fmt.Sprintf("%s: now searching for loads from: %+v", client, states))
|
||||
}
|
||||
|
||||
func sendNewPause(client string, pause time.Time) error {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"local/truckstop/config"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -64,7 +64,7 @@ func uploadImage(b []byte) (string, error) {
|
|||
request.Header.Set("Authorization", "Bearer "+images.AccessToken)
|
||||
request.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
|
||||
c := &http.Client{Timeout: time.Minute * 5}
|
||||
c := &http.Client{Timeout: time.Minute}
|
||||
response, err := c.Do(request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package message
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"local/truckstop/config"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ package message
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -45,28 +44,8 @@ func newMatrix(conf config.Matrix, cont string) Matrix {
|
|||
}
|
||||
}
|
||||
|
||||
func (m Matrix) closeclient(client *gomatrix.Client) {
|
||||
go func() {
|
||||
client.Client.CloseIdleConnections()
|
||||
client.StopSync()
|
||||
client.Logout()
|
||||
}()
|
||||
}
|
||||
|
||||
func (m Matrix) getclient() (*gomatrix.Client, error) {
|
||||
client, err := gomatrix.NewClient(m.homeserver, m.username, m.token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.Client = &http.Client{
|
||||
Timeout: time.Minute * 5,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
return client, nil
|
||||
return gomatrix.NewClient(m.homeserver, m.username, m.token)
|
||||
}
|
||||
|
||||
func (m Matrix) Continuation() string {
|
||||
|
|
@ -100,13 +79,12 @@ func (m *Matrix) Receive() ([]Message, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer m.closeclient(c)
|
||||
messages := make([]Message, 0)
|
||||
result, err := c.Messages(m.room, "999999999999999999", m.Continuation(), 'b', 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logtr.Verbosef("%s => {Start:%s End:%v};; %v, (%d)", m.Continuation(), result.Start, result.End, err, len(result.Chunk))
|
||||
logtr.Debugf("%s => {Start:%s End:%v};; %v, (%d)", m.Continuation(), result.Start, result.End, err, len(result.Chunk))
|
||||
m.continuation = result.End
|
||||
for _, event := range result.Chunk {
|
||||
logtr.Verbosef("matrix event: %+v", event)
|
||||
|
|
@ -122,7 +100,7 @@ func (m *Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
}
|
||||
clientChange := regexp.MustCompile("@[a-z]+$")
|
||||
logtr.Verbosef("rewriting messages based on @abc")
|
||||
logtr.Debugf("rewriting messages based on @abc")
|
||||
for i := range messages {
|
||||
if found := clientChange.FindString(messages[i].Content); found != "" {
|
||||
messages[i].Content = strings.TrimSpace(strings.ReplaceAll(messages[i].Content, found, ""))
|
||||
|
|
@ -136,7 +114,7 @@ func (m *Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
messages[i].Content = strings.TrimSpace(messages[i].Content)
|
||||
}
|
||||
logtr.Verbosef("rewriting messages based on ! CoMmAnD ...")
|
||||
logtr.Debugf("rewriting messages based on ! CoMmAnD ...")
|
||||
for i := range messages {
|
||||
if strings.HasPrefix(messages[i].Content, "!") {
|
||||
messages[i].Content = "!" + strings.TrimSpace(messages[i].Content[1:])
|
||||
|
|
@ -156,7 +134,6 @@ func (m Matrix) Remove(id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer m.closeclient(c)
|
||||
_, err = c.RedactEvent(m.room, id, &gomatrix.ReqRedact{Reason: "stale"})
|
||||
return err
|
||||
}
|
||||
|
|
@ -170,7 +147,6 @@ func (m Matrix) Update(id, text string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer m.closeclient(c)
|
||||
type MRelatesTo struct {
|
||||
EventID string `json:"event_id"`
|
||||
RelType string `json:"rel_type"`
|
||||
|
|
@ -214,7 +190,6 @@ func (m Matrix) SendTracked(text string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer m.closeclient(c)
|
||||
resp, err := c.SendText(m.room, text)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -250,14 +225,13 @@ func (m Matrix) SendImageTracked(uri string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer m.closeclient(c)
|
||||
mediaUpload, err := c.UploadToContentRepo(bytes.NewReader(b), "image/jpeg", int64(len(b)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
publicURI := mediaUpload.ContentURI
|
||||
resp, err := c.SendImage(m.room, "img", publicURI)
|
||||
logtr.Verbosef("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||
logtr.Debugf("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||
return resp.EventID, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package message
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/config"
|
||||
"local/truckstop/config"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
|
|
|||
18
todo.yaml
18
todo.yaml
|
|
@ -1,24 +1,20 @@
|
|||
todo:
|
||||
- more than NTG; blue one
|
||||
- !states emits current state
|
||||
- !states emits current state
|
||||
- TEST. Just like, refactor and test to shit.
|
||||
- try search ntg by autoinc?
|
||||
- test each !command callbacks to matrix
|
||||
- recv-as for clients so pa receives mas commands as writes
|
||||
- continuation is garbo, but I can still do better client side to avoid get-set high level
|
||||
- no hard code jpeg or have it in multiple places
|
||||
- change matrix so I test my custom logic even if I dont fetch remote
|
||||
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
||||
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
||||
- more than NTG
|
||||
- todo: filter out jobs like CA
|
||||
subtasks:
|
||||
- banlist criteria like vendors, brokers, metadata
|
||||
- set up copy for caleb, broc
|
||||
- move from main() and make more functions
|
||||
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...?
|
||||
- try search ntg by autoinc?
|
||||
- TEST. Just like, refactor and test to shit.
|
||||
- mark jobs no longer avail by modifying in matrix;; save matrix ID over dummy payload
|
||||
- TEST its falling apart
|
||||
- help() log on truckstop for stuff like perma 403
|
||||
|
|
@ -45,7 +41,7 @@ done:
|
|||
- pause until => !busy until
|
||||
- todo: maps of to+from to get location within state via api
|
||||
details: |
|
||||
curl 'https://maps.googleapis.com/maps/api/staticmap?center=Advance,NC&markers=label=A|Advance,NC&zoom=5&size=250x250&scale=2&format=jpeg&maptype=roadmap&key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' -H 'Accept: image/avif,image/webp,*/*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'DNT: 1' -H 'Alt-Used: maps.googleapis.com' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: image' -H 'Sec-Fetch-Mode: no-cors' -H 'Sec-Fetch-Site: cross-site' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'TE: trailers' > whatever.jpg; open whatever.jpg~/Go/src/gogs.inhome.blapointe.com/local/truckstop
|
||||
curl 'https://maps.googleapis.com/maps/api/staticmap?center=Advance,NC&markers=label=A|Advance,NC&zoom=5&size=250x250&scale=2&format=jpeg&maptype=roadmap&key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' -H 'Accept: image/avif,image/webp,*/*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'DNT: 1' -H 'Alt-Used: maps.googleapis.com' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: image' -H 'Sec-Fetch-Mode: no-cors' -H 'Sec-Fetch-Site: cross-site' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'TE: trailers' > whatever.jpg; open whatever.jpg~/Go/src/local/truckstop
|
||||
subtasks:
|
||||
- DONE; yandex; key 9baa3e42-c6e5-4eb5-a891-05ffcede6a25 yandex maps
|
||||
- google; key AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg
|
||||
|
|
@ -75,4 +71,4 @@ done:
|
|||
- parse jobs
|
||||
- gather jobs
|
||||
- read states
|
||||
- read email to state file from gogs.inhome.blapointe.com/local/sandbox/contact/contact
|
||||
- read email to state file from local/sandbox/contact/contact
|
||||
|
|
|
|||
Binary file not shown.
112
zip/zip.go
112
zip/zip.go
|
|
@ -1,112 +0,0 @@
|
|||
package zip
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"gogs.inhome.blapointe.com/local/truckstop/logtr"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed testdata/simplemaps_uszips_basicv1.79/uszips.csv
|
||||
var csv string
|
||||
|
||||
type Zip struct {
|
||||
Lat float64
|
||||
Lng float64
|
||||
City string
|
||||
State string
|
||||
}
|
||||
|
||||
var zips map[string]Zip
|
||||
|
||||
func init() {
|
||||
if len(zips) > 0 {
|
||||
return
|
||||
}
|
||||
zips = map[string]Zip{}
|
||||
trim := func(s string) string {
|
||||
return strings.Trim(s, `"`)
|
||||
}
|
||||
for _, line := range strings.Split(csv, "\n")[1:] {
|
||||
strs := strings.Split(line, ",")
|
||||
if len(strs) < 5 {
|
||||
continue
|
||||
}
|
||||
zip := trim(strs[0])
|
||||
lat, _ := strconv.ParseFloat(trim(strs[1]), 32)
|
||||
lng, _ := strconv.ParseFloat(trim(strs[2]), 32)
|
||||
city := trim(alphafy(strs[3]))
|
||||
state := strings.ToUpper(trim(strs[4]))
|
||||
zips[zip] = Zip{
|
||||
Lat: lat,
|
||||
Lng: lng,
|
||||
City: city,
|
||||
State: state,
|
||||
}
|
||||
}
|
||||
logtr.Infof("loaded %d zip codes", len(zips))
|
||||
}
|
||||
|
||||
func alphafy(s string) string {
|
||||
bs := make([]byte, 0, len(s)+1)
|
||||
for i := range s {
|
||||
if (s[i] < 'a' || s[i] > 'z') && (s[i] < 'A' || s[i] > 'Z') {
|
||||
} else {
|
||||
bs = append(bs, s[i])
|
||||
}
|
||||
}
|
||||
return strings.ToLower(string(bs))
|
||||
}
|
||||
|
||||
func (zip Zip) MilesTo(other Zip) int {
|
||||
// c**2 = a**2 + b**2
|
||||
// 69.2 mi per lat
|
||||
// 60.0 mi per lng
|
||||
return int(math.Sqrt(
|
||||
math.Pow(69.2*(math.Abs(zip.Lat)-math.Abs(other.Lat)), 2) +
|
||||
math.Pow(60.0*(math.Abs(zip.Lng)-math.Abs(other.Lng)), 2),
|
||||
))
|
||||
}
|
||||
|
||||
func Get(zip string) Zip {
|
||||
if z, ok := zips[zip]; ok {
|
||||
return z
|
||||
}
|
||||
zipAsI, err := strconv.Atoi(strings.Split(zip, "-")[0])
|
||||
if err != nil {
|
||||
return Zip{}
|
||||
}
|
||||
for i := 0; i < 5; i++ {
|
||||
j := i - 2
|
||||
if z2, ok := zips[strconv.Itoa(zipAsI+j)]; ok {
|
||||
return z2
|
||||
}
|
||||
}
|
||||
return Zip{}
|
||||
}
|
||||
|
||||
func GetStatesWithin(zip Zip, miles int) []string {
|
||||
states := map[string]struct{}{}
|
||||
for _, other := range zips {
|
||||
if zip.MilesTo(other) <= miles {
|
||||
states[other.State] = struct{}{}
|
||||
}
|
||||
}
|
||||
result := []string{}
|
||||
for state := range states {
|
||||
result = append(result, state)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func FromCityState(city, state string) Zip {
|
||||
city = alphafy(city)
|
||||
state = strings.ToUpper(state)
|
||||
for _, z := range zips {
|
||||
if z.City == city && z.State == state {
|
||||
return z
|
||||
}
|
||||
}
|
||||
return Zip{}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package zip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestZip(t *testing.T) {
|
||||
_ = true
|
||||
zip27006 := Get("27006")
|
||||
zip84059 := Get("84059")
|
||||
t.Logf("27006 = %+v", zip27006)
|
||||
t.Logf("84059 = %+v", zip84059)
|
||||
if zip27006.MilesTo(zip84059) < 1800 {
|
||||
t.Error("failed to compute miles from advance to ut")
|
||||
}
|
||||
sorted := func(s []string) []string {
|
||||
sort.Strings(s)
|
||||
return s
|
||||
}
|
||||
if got := GetStatesWithin(Get("27006"), 100); fmt.Sprint(sorted(got)) != fmt.Sprint(sorted([]string{"NC", "SC", "TN", "VA"})) {
|
||||
t.Error(got)
|
||||
}
|
||||
if got := FromCityState("ADVANCE", "nc"); got != zip27006 {
|
||||
t.Error(got)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue