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