Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c62d84b40a | ||
|
|
1a072fee59 | ||
|
|
c4213e697d | ||
|
|
934a306bc9 | ||
|
|
82bdbb1f3b | ||
|
|
b090cb86a5 |
@@ -223,11 +223,8 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
|
|||||||
|
|
||||||
func (ntg NTGVision) workingHours(now time.Time) bool {
|
func (ntg NTGVision) workingHours(now time.Time) bool {
|
||||||
// TODO assert M-F 9-4 EST
|
// TODO assert M-F 9-4 EST
|
||||||
location, err := time.LoadLocation("EST")
|
now = now.In(time.FixedZone("EST", -5*60*60))
|
||||||
if err != nil {
|
logtr.Debugf("ntg.workingHours: %s: weekday=%v (sun=%v, sat=%v), hour=%v (ok=9..16)", now.String(), now.Weekday(), time.Sunday, time.Saturday, now.Hour())
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
now = now.In(location)
|
|
||||||
switch now.Weekday() {
|
switch now.Weekday() {
|
||||||
case time.Sunday, time.Saturday:
|
case time.Sunday, time.Saturday:
|
||||||
return false
|
return false
|
||||||
@@ -241,8 +238,12 @@ func (ntg NTGVision) workingHours(now time.Time) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
||||||
if ntg.workingHours(time.Now()) {
|
if !ntg.workingHours(time.Now()) {
|
||||||
return nil, nil
|
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)
|
rc, err := ntg.searcher.searchStates(states)
|
||||||
@@ -260,12 +261,22 @@ func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
|||||||
|
|
||||||
var ntgjobs []ntgVisionJob
|
var ntgjobs []ntgVisionJob
|
||||||
err = json.Unmarshal(b, &ntgjobs)
|
err = json.Unmarshal(b, &ntgjobs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
jobs := make([]Job, len(ntgjobs))
|
jobs := make([]Job, len(ntgjobs))
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
jobs[i] = ntgjobs[i].Job()
|
jobs[i] = ntgjobs[i].Job()
|
||||||
}
|
}
|
||||||
return jobs, err
|
|
||||||
|
jobsB, err := json.Marshal(jobs)
|
||||||
|
if err == nil {
|
||||||
|
config.Get().DB().Set("ntg_last_search_states", jobsB)
|
||||||
|
logtr.Verbosef("ntg.SearchStates: in working hours so setting ntg_last_search_states: %+v", jobs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return jobs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNTGTokenKey() string {
|
func getNTGTokenKey() string {
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
|
|
||||||
func TestWorkingHoursNTG(t *testing.T) {
|
func TestWorkingHoursNTG(t *testing.T) {
|
||||||
ntg := NTGVision{}
|
ntg := NTGVision{}
|
||||||
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.Local)) {
|
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
||||||
t.Fatal("noon MST not ok")
|
t.Fatal("noon MST not ok")
|
||||||
}
|
}
|
||||||
if ntg.workingHours(time.Date(2022, 1, 27, 23, 0, 0, 0, time.Local)) {
|
if ntg.workingHours(time.Date(2022, 1, 27, 23, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
||||||
t.Fatal("midnight MST ok")
|
t.Fatal("midnight MST ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
todo:
|
todo:
|
||||||
- fast exact does not use ID in UID because they spammy
|
|
||||||
- from states to zip codes w/ range
|
|
||||||
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
|
||||||
- more than NTG; blue one
|
- more than NTG; blue one
|
||||||
- !states emits current state
|
- !states emits current state
|
||||||
- test each !command callbacks to matrix
|
- test each !command callbacks to matrix
|
||||||
@@ -14,7 +11,11 @@ todo:
|
|||||||
subtasks:
|
subtasks:
|
||||||
- banlist criteria like vendors, brokers, metadata
|
- banlist criteria like vendors, brokers, metadata
|
||||||
- set up copy for caleb, broc
|
- set up copy for caleb, broc
|
||||||
|
- move from main() and make more functions
|
||||||
done:
|
done:
|
||||||
|
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
||||||
|
- from states to zip codes w/ range
|
||||||
|
- fast exact does not use ID in UID because they spammy
|
||||||
- fast exact is dumb or...?
|
- fast exact is dumb or...?
|
||||||
- try search ntg by autoinc?
|
- try search ntg by autoinc?
|
||||||
- TEST. Just like, refactor and test to shit.
|
- TEST. Just like, refactor and test to shit.
|
||||||
|
|||||||
Reference in New Issue
Block a user