Compare commits
No commits in common. "395280a3639855b8294d8e96035edb52e37d6dcf" and "21f872d77c05d48d351b9986ab038af4397ec086" have entirely different histories.
395280a363
...
21f872d77c
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,3 @@
|
|||||||
rss.iml
|
rss.iml
|
||||||
rss
|
rss
|
||||||
fetchdapenti
|
fetchdapenti
|
||||||
/run.sh
|
|
||||||
/sendmail
|
|
@ -88,10 +88,6 @@ func fetch(u string) (r rss2.Item) {
|
|||||||
var hadSend = safety.NewMap[string, struct{}]()
|
var hadSend = safety.NewMap[string, struct{}]()
|
||||||
|
|
||||||
func downAndSendMail(doc *goquery.Document, title string) {
|
func downAndSendMail(doc *goquery.Document, title string) {
|
||||||
if err := mail.CheckEnv(); err != nil {
|
|
||||||
log.Println("err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
type m struct {
|
type m struct {
|
||||||
tit string
|
tit string
|
||||||
content string
|
content string
|
||||||
|
16
mail/mail.go
16
mail/mail.go
@ -7,29 +7,23 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cm, subjectParam, contentParam, fileParam string
|
func SendMail(subject string, content string, files ...string) error {
|
||||||
|
cm := os.Getenv("mail_cmd_path")
|
||||||
func CheckEnv() error {
|
|
||||||
cm = os.Getenv("mail_cmd_path")
|
|
||||||
if cm == "" {
|
if cm == "" {
|
||||||
return errors.New("cmd can't empty")
|
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 == "" {
|
if subjectParam == "" {
|
||||||
return errors.New("title param name empty")
|
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 == "" {
|
if contentParam == "" {
|
||||||
return errors.New("content param name emtpy")
|
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 == "" {
|
if fileParam == "" {
|
||||||
return errors.New("file empty")
|
return errors.New("file empty")
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func SendMail(subject string, content string, files ...string) error {
|
|
||||||
v := []string{subjectParam, subject, contentParam, content}
|
v := []string{subjectParam, subject, contentParam, content}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if f != "" {
|
if f != "" {
|
||||||
|
17
main.go
17
main.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -63,45 +62,39 @@ 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(), recentDay)
|
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(), recentDay)
|
return filterItem(s, time.Now(), 1)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
func bbcLearn(w http.ResponseWriter, _ *http.Request) {
|
func bbcLearn(w http.ResponseWriter, _ *http.Request) {
|
||||||
io.WriteString(w, fetch("https://www.bbc.co.uk/learningenglish/chinese", func(s string) string {
|
io.WriteString(w, fetch("https://www.bbc.co.uk/learningenglish/chinese", func(s string) string {
|
||||||
return bbclearn.LearnParse(s, recentDay)
|
return bbclearn.LearnParse(s, 1)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
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(), recentDay)
|
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(), recentDay)
|
return filterItem(s, time.Now(), 1)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
var recentDay = 1
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
port := os.Getenv("port")
|
port := os.Getenv("port")
|
||||||
if port == "" {
|
if port == "" {
|
||||||
port = ":80"
|
port = ":80"
|
||||||
}
|
}
|
||||||
day := os.Getenv("rss_recent_day")
|
|
||||||
if day != "" {
|
|
||||||
recentDay = str.ToInt[int](day)
|
|
||||||
}
|
|
||||||
time.Local = time.FixedZone("CST", 3600*8)
|
time.Local = time.FixedZone("CST", 3600*8)
|
||||||
http.HandleFunc("/pentitugua", penti) //喷嚏图挂
|
http.HandleFunc("/pentitugua", penti) //喷嚏图挂
|
||||||
http.HandleFunc("/zhihuDaily", zhihuDaily) //知乎日报
|
http.HandleFunc("/zhihuDaily", zhihuDaily) //知乎日报
|
||||||
|
Loading…
Reference in New Issue
Block a user