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 @@
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 = ` -你想看到什么内容呢? + + +
+ + + +
+ +
+