Compare commits
3 Commits
8e30297639
...
013b7a533d
Author | SHA1 | Date | |
---|---|---|---|
013b7a533d | |||
233738f52f | |||
d675a17741 |
|
@ -1,9 +1,7 @@
|
||||||
package bbclearn
|
package bbclearn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
strings2 "github.com/fthvgb1/wp-go/helper/strings"
|
|
||||||
"github.com/fthvgb1/wp-go/rss2"
|
"github.com/fthvgb1/wp-go/rss2"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -18,6 +16,9 @@ func LearnParse(s string, recentDay int) string {
|
||||||
var item []rss2.Item
|
var item []rss2.Item
|
||||||
item = append(item, full(document, recentDay))
|
item = append(item, full(document, recentDay))
|
||||||
item = append(item, items(document, recentDay)...)
|
item = append(item, items(document, recentDay)...)
|
||||||
|
if len(item) < 1 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
rss := rss2.Rss2{
|
rss := rss2.Rss2{
|
||||||
Title: "BBC 英语教学",
|
Title: "BBC 英语教学",
|
||||||
Link: "https://www.bbc.co.uk/learningenglish/chinese/",
|
Link: "https://www.bbc.co.uk/learningenglish/chinese/",
|
||||||
|
@ -27,21 +28,25 @@ func LearnParse(s string, recentDay int) string {
|
||||||
return rss.GetXML()
|
return rss.GetXML()
|
||||||
}
|
}
|
||||||
|
|
||||||
func dateFilter(u string, recentDay int) (r bool) {
|
func parseTime(u string) (date time.Time, err error) {
|
||||||
uu := strings.Split(u, "-")
|
uu := strings.Split(u, "-")
|
||||||
if len(uu) < 2 {
|
if len(uu) < 2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
date, err := time.Parse("060102", uu[len(uu)-1])
|
date, err = time.Parse("060102", uu[len(uu)-1])
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func dateFilter(u string, recentDay int) (r bool) {
|
||||||
|
date, err := parseTime(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if t.Year() != date.Year() || t.Month() != date.Month() {
|
if t.Sub(date).Hours()/24-float64(recentDay) > 0 {
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Println(time.Now().Day()-recentDay, date.Day())
|
|
||||||
if t.Day()-recentDay > date.Day() {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r = true
|
r = true
|
||||||
|
@ -63,12 +68,8 @@ func fetch(u string) (r rss2.Item) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.Title = s.Find(`div[data-widget-index="3"] h3`).Text()
|
r.Title = s.Find(`div[data-widget-index="3"] h3`).Text()
|
||||||
|
date, _ := parseTime(u)
|
||||||
r.PubDate = strings.TrimSpace(s.Find(".widget-bbcle-featuresubheader").Text())
|
r.PubDate = date.Format(time.RFC1123Z)
|
||||||
r.PubDate = strings2.Replace(r.PubDate, map[string]string{
|
|
||||||
"\n": "",
|
|
||||||
})
|
|
||||||
r.PubDate = strings2.CutSpecialDuplicate(r.PubDate, " ")
|
|
||||||
r.Guid = u
|
r.Guid = u
|
||||||
r.Description = content
|
r.Description = content
|
||||||
return
|
return
|
||||||
|
|
18
main.go
18
main.go
|
@ -31,7 +31,7 @@ func fetch(u string, fn ...func(s string) string) string {
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
func dayLimit(today, forwardDay int, s, format string) string {
|
func dayLimit(now time.Time, forwardDay int, s, format string) string {
|
||||||
da := date.FindStringSubmatch(s)
|
da := date.FindStringSubmatch(s)
|
||||||
if len(da) <= 1 {
|
if len(da) <= 1 {
|
||||||
return s
|
return s
|
||||||
|
@ -40,15 +40,17 @@ func dayLimit(today, forwardDay int, s, format string) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
if today-forwardDay > t.Day() {
|
day := now.Sub(t).Hours() / 24
|
||||||
|
if day-float64(forwardDay) > 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterItem(html string, today, recentDay int) string {
|
func filterItem(html string, now time.Time, recentDay int) string {
|
||||||
return zhihuReg.ReplaceAllStringFunc(html, func(s string) string {
|
return zhihuReg.ReplaceAllStringFunc(html, func(s string) string {
|
||||||
return dayLimit(today, recentDay, s, time.RFC1123Z)
|
return dayLimit(now, recentDay, s, time.RFC1123Z)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,14 +62,14 @@ func penti(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
func zhihuDaily(w http.ResponseWriter, req *http.Request) {
|
func zhihuDaily(w http.ResponseWriter, req *http.Request) {
|
||||||
io.WriteString(w, fetch("https://feedx.best/rss/zhihudaily.xml", func(s string) string {
|
io.WriteString(w, fetch("https://feedx.best/rss/zhihudaily.xml", func(s string) string {
|
||||||
return filterItem(s, time.Now().Day(), 1)
|
return filterItem(s, time.Now(), 1)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func tjxz(w http.ResponseWriter, r *http.Request) {
|
func tjxz(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
io.WriteString(w, fetch("https://feedx.best/rss/tjxz.xml", func(s string) string {
|
io.WriteString(w, fetch("https://feedx.best/rss/tjxz.xml", func(s string) string {
|
||||||
return filterItem(s, time.Now().Day(), 0)
|
return filterItem(s, time.Now(), 0)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
func bbcLearn(w http.ResponseWriter, _ *http.Request) {
|
func bbcLearn(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
@ -78,13 +80,13 @@ func bbcLearn(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
|
||||||
func theNewYorker(w http.ResponseWriter, r *http.Request) {
|
func theNewYorker(w http.ResponseWriter, r *http.Request) {
|
||||||
io.WriteString(w, fetch("https://feedx.best/rss/newyorker.xml", func(s string) string {
|
io.WriteString(w, fetch("https://feedx.best/rss/newyorker.xml", func(s string) string {
|
||||||
return filterItem(s, time.Now().Day(), 1)
|
return filterItem(s, time.Now(), 1)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func voaLearnEnglish(w http.ResponseWriter, r *http.Request) {
|
func voaLearnEnglish(w http.ResponseWriter, r *http.Request) {
|
||||||
io.WriteString(w, fetch("https://feedx.best/rss/voalearningenglish.xml", func(s string) string {
|
io.WriteString(w, fetch("https://feedx.best/rss/voalearningenglish.xml", func(s string) string {
|
||||||
return filterItem(s, time.Now().Day(), 1)
|
return filterItem(s, time.Now(), 1)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user