48 lines
1.4 KiB
Go
Executable File
48 lines
1.4 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"local/sandbox/contact/contact"
|
|
"log"
|
|
"regexp"
|
|
)
|
|
|
|
func main() {
|
|
config := NewConfig()
|
|
emailer := &contact.Emailer{
|
|
IMAP: config.EmailIMAP,
|
|
From: config.EmailUser,
|
|
Password: config.EmailPass,
|
|
}
|
|
emails, err := emailer.Read()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
patterns := regexp.MustCompile(config.AccountsPattern)
|
|
antipatterns := regexp.MustCompile(config.AccountsAntiPattern)
|
|
for email := range emails {
|
|
transactions, err := Scrape(email, config.Banks)
|
|
if err != nil {
|
|
log.Println("failed to scrape email:", err)
|
|
}
|
|
for _, transaction := range transactions {
|
|
if !patterns.MatchString(transaction.Account) {
|
|
log.Printf("skipping unmatching account pattern %q vs %q", config.AccountsPattern, transaction.Account)
|
|
continue
|
|
}
|
|
if antipatterns.MatchString(transaction.Account) {
|
|
log.Printf("skipping match account antipattern %q vs %q", config.AccountsAntiPattern, transaction.Account)
|
|
continue
|
|
}
|
|
if _, err := config.Storage.Get(transaction.ID); err == nil {
|
|
log.Println("skipping duplicate transaction:", transaction)
|
|
} else {
|
|
if err := Upload(config, transaction); err != nil {
|
|
log.Println("failed to upload transaction", transaction, ":", err)
|
|
} else if err := config.Storage.Set(transaction.ID, []byte(transaction.String())); err != nil {
|
|
log.Println("failed to log", transaction, ":", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|