fix: randomize rss fetching timer and user-agent
Some checks are pending
build / build (push) Waiting to run
Some checks are pending
build / build (push) Waiting to run
This commit is contained in:
parent
3417626fa0
commit
4c93b0c1ca
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue