fix: randomize rss fetching timer and user-agent
Some checks are pending
build / build (push) Waiting to run

This commit is contained in:
Viktor Varland 2026-02-27 23:10:25 +01:00
parent 3417626fa0
commit 4c93b0c1ca
No known key found for this signature in database
GPG key ID: 991E991EBEC46432
2 changed files with 12 additions and 2 deletions

View file

@ -315,7 +315,13 @@ func Fetch(d Download) {
}
func RssDownloader(url string) ([]byte, error) {
resp, err := http.Get(url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("failed to create RSS request: %w", err)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to fetch RSS feed: %w", err)
}

View file

@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"time"
@ -42,7 +43,10 @@ func run(cfg config.Config) {
}
for _, outlines := range opml.Body.Outline {
for _, outline := range outlines.Outlines {
for i, outline := range outlines.Outlines {
if i > 0 {
time.Sleep(time.Duration(1+rand.Float64()*4) * time.Second)
}
rssData, err := dl.RssDownloader(outline.XmlUrl)
if err != nil {
log.Printf("Failed to download RSS for %s: %v", outline.Title, err)