Compare commits

...

2 Commits

Author SHA1 Message Date
395280a363 完善 2023-07-11 14:54:17 +08:00
5a4d808f89 完善 2023-07-11 12:28:38 +08:00
4 changed files with 30 additions and 11 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
rss.iml
rss
fetchdapenti
/run.sh
/sendmail

View File

@ -88,6 +88,10 @@ func fetch(u string) (r rss2.Item) {
var hadSend = safety.NewMap[string, struct{}]()
func downAndSendMail(doc *goquery.Document, title string) {
if err := mail.CheckEnv(); err != nil {
log.Println("err", err)
return
}
type m struct {
tit string
content string

View File

@ -7,23 +7,29 @@ import (
"os/exec"
)
func SendMail(subject string, content string, files ...string) error {
cm := os.Getenv("mail_cmd_path")
var cm, subjectParam, contentParam, fileParam string
func CheckEnv() error {
cm = os.Getenv("mail_cmd_path")
if cm == "" {
return errors.New("cmd can't empty")
}
subjectParam := os.Getenv("mail_cmd_subject_param_name")
subjectParam = os.Getenv("mail_cmd_subject_param_name")
if subjectParam == "" {
return errors.New("title param name empty")
}
contentParam := os.Getenv("mail_cmd_content_param_name")
contentParam = os.Getenv("mail_cmd_content_param_name")
if contentParam == "" {
return errors.New("content param name emtpy")
}
fileParam := os.Getenv("mail_cmd_file_param_name")
fileParam = os.Getenv("mail_cmd_file_param_name")
if fileParam == "" {
return errors.New("file empty")
}
return nil
}
func SendMail(subject string, content string, files ...string) error {
v := []string{subjectParam, subject, contentParam, content}
for _, f := range files {
if f != "" {

17
main.go
View File

@ -1,6 +1,7 @@
package main
import (
str "github.com/fthvgb1/wp-go/helper/strings"
"io"
"log"
"net/http"
@ -62,39 +63,45 @@ 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(), recentDay)
}))
}
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(), 1)
return filterItem(s, time.Now(), recentDay)
}))
}
func bbcLearn(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, fetch("https://www.bbc.co.uk/learningenglish/chinese", func(s string) string {
return bbclearn.LearnParse(s, 1)
return bbclearn.LearnParse(s, recentDay)
}))
}
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(), recentDay)
}))
}
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(), recentDay)
}))
}
var recentDay = 1
func main() {
port := os.Getenv("port")
if port == "" {
port = ":80"
}
day := os.Getenv("rss_recent_day")
if day != "" {
recentDay = str.ToInt[int](day)
}
time.Local = time.FixedZone("CST", 3600*8)
http.HandleFunc("/pentitugua", penti) //喷嚏图挂
http.HandleFunc("/zhihuDaily", zhihuDaily) //知乎日报