2024/10/14 14:38:32 Error parsing RSS feed from https://ria.ru: Failed to detect feed…
- User
2024/10/14 14:38:32 Error parsing RSS feed from https://ria.ru: Failed to detect feed type
package main
import ( "bytes" "encoding/json" "fmt" "log" "net/http" "strings"
"github.com/mmcdole/gofeed")
// Article represents a news article type Article struct { Title string
json:"title"Link stringjson:"link"Description stringjson:"description"}// FilterArticles filters the articles by a list of keywords func FilterArticles(articles []*gofeed.Item, keywords []string) []Article { var filteredArticles []Article
for _, item := range articles { for _, keyword := range keywords { if strings.Contains(strings.ToLower(item.Title), strings.ToLower(keyword)) || strings.Contains(strings.ToLower(item.Description), strings.ToLower(keyword)) { filteredArticles = append(filteredArticles, Article{ Title: item.Title, Link: item.Link, Description: item.Description, }) break } } } return filteredArticles}
// SendWebhook sends the filtered articles to a webhook URL func SendWebhook(webhookURL string, articles []Article) error { payload, err := json.Marshal(articles) if err != nil { return err }
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(payload)) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return fmt.Errorf("failed to send webhook: %s", resp.Status) } return nil}
func fetchAndFilterRSS(rssURL string, keywords []string) []Article { fp := gofeed.NewParser() feed, err := fp.ParseURL(rssURL) if err != nil { log.Fatalf("Error parsing RSS feed from %s: %v", rssURL, err) }
// Filter articles based on keywords return FilterArticles(feed.Items, keywords)}
func main() { rssFeeds := []string{ "https://ria.ru", "https://ria.ru/politics/", "https://ria.ru/economy/", "https://ria.ru/world/", } webhookURL := "https://canary.discord.com/api/webhooks/1292843976080228363/Kzn3yJJGTRb46reJhh0jgYTZuORGB6o5cegT9NRiCCw77ViRtHveOrxHTWeXNEOxPhe-" // Replace with your webhook URL keywords := []string{"Россия", "политика", "экономика", "мир"} // Example keywords var allArticles []Article
- Assistant
- User
Unused variable 'webhookURL'
потом найденные данные должны отправляться вебхуком
- Assistant
- User
нет есть только
"https://ria.ru", "https://ria.ru/politics/", "https://ria.ru/economy/", "https://ria.ru/world/",xml нету парси эти сайты
- Assistant
- User
2024/10/14 14:53:38 Error sending webhook: failed to send webhook: 400 Bad Request
- Assistant