feat(scraper): bound article enrichment diagnostics (#40)

This commit is contained in:
2026-11-25 00:07:45 +01:00
parent a3c70670f6
commit 6883b3976b
53 changed files with 4049 additions and 68 deletions

View File

@ -5,23 +5,42 @@ import (
"encoding/xml"
"errors"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
"github.com/tradarr/backend/internal/scraper"
"github.com/tradarr/backend/internal/scraper/sourcehttp"
)
type YahooFinance struct {
client *http.Client
client *http.Client
diagnostics io.Writer
}
func New() *YahooFinance {
return &YahooFinance{
client: &http.Client{Timeout: 15 * time.Second},
client: &http.Client{Transport: sourcehttp.NewTransport(nil, nil), Timeout: 15 * time.Second,
CheckRedirect: func(r *http.Request, via []*http.Request) error {
if len(via) == 0 || len(via) >= 3 || r.URL.Scheme != "https" || r.URL.User != nil || r.URL.Host != via[0].URL.Host {
return http.ErrUseLastResponse
}
return nil
}},
}
}
// NewWithClient injects transport/diagnostic sinks without replacing ingestion.
func NewWithClient(client *http.Client, diagnostics io.Writer) *YahooFinance {
y := New()
if client != nil {
y.client = client
}
y.diagnostics = diagnostics
return y
}
func (y *YahooFinance) Name() string { return "stocktwits" } // garde le même type en DB
type rssFeed struct {
@ -77,7 +96,11 @@ func (y *YahooFinance) fetchSymbol(ctx context.Context, symbol string) (articles
if len(safeSymbol) > 64 {
safeSymbol = safeSymbol[:64]
}
fmt.Printf("yahoofinance symbol=%s yahoo_symbol=%s status=%d articles=%d outcome=%s\n", safeSymbol, safeSymbol, status, len(articles), outcome)
writer := y.diagnostics
if writer == nil {
writer = os.Stdout
}
fmt.Fprintf(writer, "yahoofinance symbol=%s yahoo_symbol=%s status=%d articles=%d outcome=%s\n", safeSymbol, safeSymbol, status, len(articles), outcome)
}()
url := fmt.Sprintf(
"https://feeds.finance.yahoo.com/rss/2.0/headline?s=%s&region=US&lang=en-US",