From f04c9d167929931ac6fb3b7a5bf4b399b15cb939 Mon Sep 17 00:00:00 2001 From: xing Date: Sun, 9 Jul 2023 23:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BDbbc=E9=9F=B3=E9=A2=91?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E9=82=AE=E4=BB=B6=20=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bbclearn/bbc.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bbclearn/bbc.go b/bbclearn/bbc.go index 812a9b2..58e9927 100644 --- a/bbclearn/bbc.go +++ b/bbclearn/bbc.go @@ -3,6 +3,7 @@ package bbclearn import ( "github.com/PuerkitoBio/goquery" "github.com/fthvgb1/wp-go/rss2" + "github.com/fthvgb1/wp-go/safety" "io" "log" "net/http" @@ -77,10 +78,15 @@ func fetch(u string) (r rss2.Item) { r.PubDate = date.Format(time.RFC1123Z) r.Guid = u r.Description = content - go downAndSendMail(dom, r.Title) + if _, ok := hadSend.Load(r.Title); !ok { + go downAndSendMail(dom, r.Title) + } + return } +var hadSend = safety.NewMap[string, struct{}]() + func downAndSendMail(doc *goquery.Document, title string) { type m struct { tit string @@ -117,6 +123,7 @@ func downAndSendMail(doc *goquery.Document, title string) { return } mail.SendMail(mm.tit, mm.content, mm.f...) + hadSend.Store(mm.tit, struct{}{}) for _, s := range mm.f { err := os.Remove(s) if err != nil {