fix bug
This commit is contained in:
parent
233738f52f
commit
013b7a533d
@ -1,7 +1,6 @@
|
||||
package bbclearn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/fthvgb1/wp-go/rss2"
|
||||
"net/http"
|
||||
@ -47,11 +46,7 @@ func dateFilter(u string, recentDay int) (r bool) {
|
||||
return
|
||||
}
|
||||
t := time.Now()
|
||||
if t.Year() != date.Year() || t.Month() != date.Month() {
|
||||
return
|
||||
}
|
||||
fmt.Println(time.Now().Day()-recentDay, date.Day())
|
||||
if t.Day()-recentDay > date.Day() {
|
||||
if t.Sub(date).Hours()/24-float64(recentDay) > 0 {
|
||||
return
|
||||
}
|
||||
r = true
|
||||
|
18
main.go
18
main.go
@ -31,7 +31,7 @@ func fetch(u string, fn ...func(s string) string) string {
|
||||
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)
|
||||
if len(da) <= 1 {
|
||||
return s
|
||||
@ -40,15 +40,17 @@ func dayLimit(today, forwardDay int, s, format string) string {
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
if today-forwardDay > t.Day() {
|
||||
day := now.Sub(t).Hours() / 24
|
||||
if day-float64(forwardDay) > 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
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 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) {
|
||||
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) {
|
||||
|
||||
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) {
|
||||
@ -78,13 +80,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().Day(), 1)
|
||||
return filterItem(s, time.Now(), 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().Day(), 1)
|
||||
return filterItem(s, time.Now(), 1)
|
||||
}))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user