Проверка на наличие HTML тэгов

This commit is contained in:
B4D_US3R 2025-03-06 14:34:59 +05:00
parent 7d673bfa17
commit 9d3ed1cd8d

14
main.go
View file

@ -7,6 +7,7 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"time" "time"
"github.com/go-yaml/yaml" "github.com/go-yaml/yaml"
@ -47,6 +48,11 @@ func getDataFromConfig(path string) *mastodon.Config {
return config return config
} }
func hasHTMLTags(s string) bool {
re := regexp.MustCompile(`<(?i)[a-z][a-z0-9]*[^>]*>`)
return re.MatchString(s)
}
func getKikiConfig(path string) KikiSettings { func getKikiConfig(path string) KikiSettings {
var kikiSettings KikiSettings var kikiSettings KikiSettings
kikiConfigFile, err := os.ReadFile(path) kikiConfigFile, err := os.ReadFile(path)
@ -176,9 +182,11 @@ func main() {
for range ticker.C { for range ticker.C {
news := newsText(kikiConfig.RSSUri) news := newsText(kikiConfig.RSSUri)
if news[0].GUID != lastGUID { if news[0].GUID != lastGUID {
createPost(news[0].Description) if !hasHTMLTags(news[0].Description) {
lastGUID = news[0].GUID createPost(news[0].Description)
log.Println("Пост отправлен") lastGUID = news[0].GUID
log.Println("Пост отправлен")
}
} }
/*for _, item := range newsText(kikiConfig.RSSUri) { /*for _, item := range newsText(kikiConfig.RSSUri) {
if item.GUID == lastGUID { if item.GUID == lastGUID {