diff --git a/api/api.go b/api/api.go index 27d7764..391262e 100644 --- a/api/api.go +++ b/api/api.go @@ -13,47 +13,6 @@ import ( query "github.com/PuerkitoBio/goquery" ) -// Weather site data -type Weather struct { - City string - Temp string - Weather string - Air string - Humidity string - Wind string - Limit string - Note string -} - -// One site info -type One struct { - Date string - ImgURL string - Sentence string -} - -// English info -type English struct { - ImgURL string - Sentence string -} - -// Poem info -type Poem struct { - Title string `json:"title"` - Dynasty string `json:"dynasty"` - Author string `json:"author"` - Content []string `json:"content"` -} - -// PoemRes response data -type PoemRes struct { - Status string `json:"status"` - Data struct { - Origin Poem `json:"origin"` - } `json:"data"` -} - // CreateClient a http func CreateClient() *http.Client { tr := &http.Transport{ @@ -157,12 +116,6 @@ func GetPoem() Poem { return resJSON.Data.Origin } -// Wallpaper data -type Wallpaper struct { - Title string - ImgURL string -} - // GetWallpaper from bing func GetWallpaper() Wallpaper { url := "https://bing.ioliu.cn/" @@ -175,3 +128,15 @@ func GetWallpaper() Wallpaper { ImgURL: imgURL, } } + +// GetTrivia data +func GetTrivia() Trivia { + url := "http://www.lengdou.net/random" + doc := FetchHTML(url) + wrap := doc.Find(".container .media .media-body") + imgURL, _ := wrap.Find(".topic-img img").Attr("src") + return Trivia{ + ImgURL: imgURL, + Description: strings.Split(wrap.Find(".topic-content").Text(), "#")[0], + } +} diff --git a/api/type.go b/api/type.go new file mode 100644 index 0000000..2c62af5 --- /dev/null +++ b/api/type.go @@ -0,0 +1,54 @@ +package api + +// Weather site data +type Weather struct { + City string + Temp string + Weather string + Air string + Humidity string + Wind string + Limit string + Note string +} + +// One site info +type One struct { + Date string + ImgURL string + Sentence string +} + +// English info +type English struct { + ImgURL string + Sentence string +} + +// Poem info +type Poem struct { + Title string `json:"title"` + Dynasty string `json:"dynasty"` + Author string `json:"author"` + Content []string `json:"content"` +} + +// PoemRes response data +type PoemRes struct { + Status string `json:"status"` + Data struct { + Origin Poem `json:"origin"` + } `json:"data"` +} + +// Wallpaper data +type Wallpaper struct { + Title string + ImgURL string +} + +// Trivia info +type Trivia struct { + ImgURL string + Description string +} diff --git a/daily.html b/daily.html index 79ae211..12b4b41 100644 --- a/daily.html +++ b/daily.html @@ -10,6 +10,8 @@

{{one.Date}}

{{weather.City}}

+
❣️
+
天气:{{weather.Weather}}
温度:{{weather.Temp}}
@@ -19,28 +21,43 @@

{{weather.City}}

限行:{{weather.Limit}}
提示:{{weather.Note}}
-

+
+
📝
+
  {{english.Sentence}}
-

+
+
📖
+
{{poem.Title}}
{{poem.Dynasty}} {{poem.Author}}

{{poem.Content}}
-

+
+
🔔
+
  {{one.Sentence}}
-

+
+
🏞
+
  {{wallpaper.Title}}
+
+
📚
+
+
+
+
  {{trivia.Description}}
+


diff --git a/html.go b/html.go index 491f90a..a474130 100644 --- a/html.go +++ b/html.go @@ -2,5 +2,68 @@ package main // HTML for email template const HTML = ` -你想看到什么内容呢? + + + + + + + 每日一暖, 温情一生 + + +
+

{{one.Date}}

+

{{weather.City}}

+
❣️
+
+
+
天气:{{weather.Weather}}
+
温度:{{weather.Temp}}
+
湿度:{{weather.Humidity}}
+
风向:{{weather.Wind}}
+
空气:{{weather.Air}}
+
限行:{{weather.Limit}}
+
提示:{{weather.Note}}
+
+
+
📝
+
+
+
+
  {{english.Sentence}}
+
+
+
📖
+
+
+
{{poem.Title}}
+
{{poem.Dynasty}} {{poem.Author}}
+
+
{{poem.Content}}
+
+
+
🔔
+
+
+
+
  {{one.Sentence}}
+
+
+
🏞
+
+
+
+
  {{wallpaper.Title}}
+
+
+
📚
+
+
+
+
  {{trivia.Description}}
+
+
+

+ + ` diff --git a/main.go b/main.go index 8689d69..1b1988c 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,7 @@ func batchSendMail() { english := api.GetEnglish() poem := api.GetPoem() wallpaper := api.GetWallpaper() + trivia := api.GetTrivia() users := getUsers("MAIL_TO") if len(users) == 0 { @@ -80,6 +81,7 @@ func batchSendMail() { "english": english, "poem": poem, "wallpaper": wallpaper, + "trivia": trivia, } html := generateHTML(HTML, datas)