scrape alerts from chase
parent
205879fc3b
commit
eead63ecb6
22
config.go
22
config.go
|
|
@ -1,6 +1,9 @@
|
|||
package main
|
||||
|
||||
import "local/args"
|
||||
import (
|
||||
"local/args"
|
||||
"local/storage"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
EmailUser string
|
||||
|
|
@ -8,8 +11,11 @@ type Config struct {
|
|||
EmailIMAP string
|
||||
TodoAddr string
|
||||
TodoPass string
|
||||
Storage storage.DB
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func NewConfig() Config {
|
||||
as := args.NewArgSet()
|
||||
|
||||
|
|
@ -18,15 +24,27 @@ func NewConfig() Config {
|
|||
as.Append(args.STRING, "emailimap", "email imap", "imap.gmail.com:993")
|
||||
as.Append(args.STRING, "todoaddr", "todo addr", "https://todo-server.remote.blapointe.com")
|
||||
as.Append(args.STRING, "todopass", "todo pass", "gJtEXbbLHLf54yS9EdujtVN2n6Y")
|
||||
as.Append(args.STRING, "store", "store type", "map")
|
||||
as.Append(args.STRING, "storeaddr", "store addr", "/tmp/store")
|
||||
as.Append(args.STRING, "storeuser", "store user", "")
|
||||
as.Append(args.STRING, "storepass", "store pass", "")
|
||||
|
||||
if err := as.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return Config{
|
||||
|
||||
storage, err := storage.New(storage.TypeFromString(as.GetString("store")), as.GetString("storeaddr"), as.GetString("storeuser"), as.GetString("storepass"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
config = Config{
|
||||
EmailUser: as.GetString("emailuser"),
|
||||
EmailPass: as.GetString("emailpass"),
|
||||
EmailIMAP: as.GetString("emailimap"),
|
||||
TodoAddr: as.GetString("todoaddr"),
|
||||
TodoPass: as.GetString("todopass"),
|
||||
Storage: storage,
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
|
|
|||
12
scrape.go
12
scrape.go
|
|
@ -4,12 +4,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/mail"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type scraper interface {
|
||||
|
|
@ -32,7 +29,6 @@ func buildScraper(m *mail.Message) (scraper, error) {
|
|||
if !containsAny(subject, "transaction", "report", "Transaction") {
|
||||
return nil, errors.New("cannot build scraper for subject " + subject)
|
||||
}
|
||||
log.Printf("%+v", m.Header)
|
||||
from := fmt.Sprint(m.Header["From"])
|
||||
if strings.Contains(from, "Chase") {
|
||||
return newChaseScraper(), nil
|
||||
|
|
@ -81,13 +77,7 @@ func (c *chaseScraper) scrape(m *mail.Message) ([]*Transaction, error) {
|
|||
}
|
||||
transactions := make([]*Transaction, len(results["amount"]))
|
||||
for i := range results["amount"] {
|
||||
transactions[i] = &Transaction{
|
||||
Amount: results["amount"][i],
|
||||
Account: results["account"][i],
|
||||
Bank: Chase,
|
||||
Date: fmt.Sprint(m.Header["Date"]),
|
||||
ID: uuid.New().String(), // TODO random based on date, amount, account, and bank so find dupes
|
||||
}
|
||||
transactions[i] = NewTransaction(results["amount"][i], results["account"][i], fmt.Sprint(m.Header["Date"]), Chase)
|
||||
}
|
||||
return transactions, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
ID string
|
||||
|
|
@ -13,3 +16,14 @@ type Transaction struct {
|
|||
func (t *Transaction) String() string {
|
||||
return fmt.Sprint(*t)
|
||||
}
|
||||
|
||||
func NewTransaction(amount, account, date string, bank Bank) *Transaction {
|
||||
t := &Transaction{
|
||||
Amount: amount,
|
||||
Account: account,
|
||||
Bank: bank,
|
||||
Date: date,
|
||||
}
|
||||
t.ID = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprint(t))))
|
||||
return t
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue