-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
61 lines (49 loc) · 1.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"log"
"os"
"github.com/caarlos0/env/v9"
miniflux "github.com/skatkov/miniflux-email-client/internal/client"
"github.com/skatkov/miniflux-email-client/internal/emailer"
)
var (
sendTo = os.Getenv("SEND_TO")
err error
)
func main() {
smtpConfig := emailer.SMTPConfig{}
if err = env.Parse(&smtpConfig); err != nil {
log.Fatalf("failed parsing ENV variables for SMTP: %+v\n", err)
}
mailer := emailer.NewEmailer(smtpConfig, emailer.HTML)
minifluxConfig := miniflux.MinifluxConfig{}
if err = env.Parse(&minifluxConfig); err != nil {
log.Fatalf("failed parsing ENV variables for miniflux: %+v\n", err)
}
client := miniflux.NewClient(minifluxConfig)
if minifluxConfig.CategoryName != "" {
log.Printf("categoryName set to: %v", minifluxConfig.CategoryName)
err = client.SetCategoryID(minifluxConfig.CategoryName)
if err != nil {
log.Fatalf("failed to set categoryId: %v", err)
return
}
} else {
log.Printf("categoryName is not set, fetching all entries")
}
entries, err := client.GetUnreadEntries(minifluxConfig.Limit)
if err != nil {
log.Fatalf("failed to fetch RSS updates: %v", err)
return
}
log.Printf("sending email")
err = mailer.Send(sendTo, &minifluxConfig.CategoryName, entries)
if err != nil {
log.Fatalf("failed to send, due to an error: %v", err)
return
}
err = client.MarkAsRead(entries)
if err != nil {
log.Fatalf("failed to mark RSS updates as read, due to an error: %v", err)
}
}