remove email scrape
parent
6569631928
commit
5a4bcecac7
13
config.json
13
config.json
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"Name": "pa",
|
"Name": "pa",
|
||||||
"Interval": {
|
"Interval": {
|
||||||
"Email": "10s..30s",
|
"Input": "10s..30s",
|
||||||
"OK": "6h0m0s..6h0m0s",
|
"OK": "6h0m0s..6h0m0s",
|
||||||
"Error": "6h0m0s..6h0m0s"
|
"Error": "6h0m0s..6h0m0s"
|
||||||
},
|
},
|
||||||
|
|
@ -34,14 +34,5 @@
|
||||||
"Username": "noeasyrunstrucking@gmail.com",
|
"Username": "noeasyrunstrucking@gmail.com",
|
||||||
"Password": "thumper123"
|
"Password": "thumper123"
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"Emailer": {
|
|
||||||
"From": "breellocaldev@gmail.com",
|
|
||||||
"SMTP": "",
|
|
||||||
"POP3": "",
|
|
||||||
"IMAP": "imap.gmail.com:993",
|
|
||||||
"Password": "gojfkkfrkmtxzyro",
|
|
||||||
"Limit": 0
|
|
||||||
},
|
|
||||||
"EmailerEnabled": false
|
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,6 @@ package config
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/sandbox/contact/contact"
|
|
||||||
"local/storage"
|
"local/storage"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -12,7 +11,7 @@ import (
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string
|
||||||
Interval struct {
|
Interval struct {
|
||||||
Email Duration
|
Input Duration
|
||||||
OK Duration
|
OK Duration
|
||||||
Error Duration
|
Error Duration
|
||||||
}
|
}
|
||||||
|
|
@ -40,8 +39,6 @@ type Config struct {
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Emailer contact.Emailer
|
|
||||||
EmailerEnabled bool
|
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
db storage.DB
|
db storage.DB
|
||||||
|
|
|
||||||
37
main.go
37
main.go
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"local/storage"
|
"local/storage"
|
||||||
"local/truckstop/broker"
|
"local/truckstop/broker"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
|
@ -12,7 +11,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -23,17 +21,10 @@ func main() {
|
||||||
lock := &sync.Mutex{}
|
lock := &sync.Mutex{}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(config.Get().Interval.Email.Get())
|
time.Sleep(config.Get().Interval.Input.Get())
|
||||||
if err := config.Refresh(); err != nil {
|
if err := config.Refresh(); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
} else {
|
} else {
|
||||||
if config.Get().EmailerEnabled {
|
|
||||||
lock.Lock()
|
|
||||||
if err := email(); err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
}
|
|
||||||
lock.Unlock()
|
|
||||||
}
|
|
||||||
if config.Get().Message.Matrix.ReceiveEnabled {
|
if config.Get().Message.Matrix.ReceiveEnabled {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
if err := matrixrecv(); err != nil {
|
if err := matrixrecv(); err != nil {
|
||||||
|
|
@ -94,32 +85,6 @@ func setNewStates(states map[config.State]struct{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func email() error {
|
|
||||||
log.Printf("checking email...")
|
|
||||||
ch, err := config.Get().Emailer.ReadIMAP()
|
|
||||||
if err != nil {
|
|
||||||
ch, err = config.Get().Emailer.ReadIMAP()
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
states := map[config.State]struct{}{}
|
|
||||||
for email := range ch {
|
|
||||||
if len(states) > 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !strings.Contains(email.Header.Get("From"), config.Get().Client) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
b, _ := ioutil.ReadAll(email.Body)
|
|
||||||
for _, state := range parseOutStates(b) {
|
|
||||||
states[state] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setNewStates(states)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseOutStates(b []byte) []config.State {
|
func parseOutStates(b []byte) []config.State {
|
||||||
var states []config.State
|
var states []config.State
|
||||||
var state config.State
|
var state config.State
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
todo:
|
todo:
|
||||||
- send matrix msg on config change
|
|
||||||
- rm email
|
|
||||||
- modify old items once no longer available
|
- modify old items once no longer available
|
||||||
- many users -> 1 ntg query
|
- many users -> 1 ntg query
|
||||||
- accept after date
|
- accept after date
|
||||||
|
|
@ -18,6 +16,8 @@ todo:
|
||||||
- accept states via element for one system
|
- accept states via element for one system
|
||||||
- set up copy for caleb, broc
|
- set up copy for caleb, broc
|
||||||
done:
|
done:
|
||||||
|
- rm email
|
||||||
|
- send matrix msg on config change
|
||||||
- setup pa on element
|
- setup pa on element
|
||||||
- configurable email interval
|
- configurable email interval
|
||||||
- jitter on intervals, including dedicated err span
|
- jitter on intervals, including dedicated err span
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue