Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (53 loc) · 1.44 KB
/
Copy pathmain.go
File metadata and controls
60 lines (53 loc) · 1.44 KB
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
// DomkerService project main.go
package main
import (
"DomkerService/notification/config"
"DomkerService/notification/email"
"DomkerService/notification/watcher"
"fmt"
"strconv"
"time"
)
var timeline time.Time
func tickCheckNewNotes(seconds time.Duration, d watcher.Douban, e email.Mail, c *config.Config) {
ticker := time.Tick(time.Second * seconds)
checkNewNotes(d, e, c)
for _ = range ticker {
checkNewNotes(d, e, c)
//fmt.Println("Now is ", now)
}
}
func checkNewNotes(d watcher.Douban, e email.Mail, c *config.Config) {
notes := d.CheckNewNote(timeline)
if timeline.IsZero() {
timeline = d.GetTimeLine(notes)
notes = d.FilterNotes(notes, timeline)
}
body := ""
for _, note := range notes {
note.Content = d.GetNoteDetail(note.Url)
body += d.ConvertEmailBody(note)
}
if len(notes) > 0 {
timeline = notes[0].CreateTime
title := "[豆瓣]发现" + c.GetDoubanUser() + "有" + strconv.Itoa(len(notes)) + "个新日记"
content := d.ConvertEmailContent(body)
err := e.Send(c.GetEmailReceiver(), title, content, "html")
if err != nil {
fmt.Println(err)
}
fmt.Println(time.Now(), title)
} else {
fmt.Println("checkNewNotes no result.", time.Now())
}
}
func main() {
c := config.GetConfig()
e := email.Mail{}
e.Init(c)
douban := watcher.Douban{}
douban.Init(c.GetDoubanUser())
interval := time.Duration(c.GetEmailInterval()) * time.Minute
tickCheckNewNotes(interval, douban, e, c)
fmt.Println("send email end")
}