feat(bloomberg): enrich article content for summaries (#36)
This commit is contained in:
@ -9,6 +9,8 @@ import (
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
)
|
||||
|
||||
var _ scraper.ArticleEnricher = (*DynamicBloomberg)(nil)
|
||||
|
||||
type DynamicBloomberg struct {
|
||||
repo *models.Repository
|
||||
enc *crypto.Encryptor
|
||||
@ -22,27 +24,40 @@ func NewDynamic(repo *models.Repository, enc *crypto.Encryptor, scraperURL strin
|
||||
func (d *DynamicBloomberg) Name() string { return "bloomberg" }
|
||||
|
||||
func (d *DynamicBloomberg) Scrape(ctx context.Context, symbols []string) ([]scraper.Article, error) {
|
||||
username, password, err := d.credentials()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(d.scraperURL).ScrapeWithCredentials(ctx, username, password, symbols)
|
||||
}
|
||||
func (d *DynamicBloomberg) Enrich(ctx context.Context, articles []scraper.Article) ([]scraper.Article, error) {
|
||||
if len(articles) == 0 {
|
||||
return []scraper.Article{}, nil
|
||||
}
|
||||
username, password, err := d.credentials()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(d.scraperURL).EnrichWithCredentials(ctx, username, password, articles)
|
||||
}
|
||||
func (d *DynamicBloomberg) credentials() (string, string, error) {
|
||||
source, err := d.repo.GetSourceByType("bloomberg")
|
||||
if err != nil || source == nil {
|
||||
return nil, fmt.Errorf("bloomberg source not found")
|
||||
return "", "", fmt.Errorf("bloomberg source not found")
|
||||
}
|
||||
|
||||
cred, err := d.repo.GetCredentials(source.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get bloomberg credentials: %w", err)
|
||||
return "", "", fmt.Errorf("bloomberg credentials unavailable")
|
||||
}
|
||||
if cred == nil || cred.Username == "" {
|
||||
return nil, fmt.Errorf("bloomberg credentials not configured — configure them in the admin panel")
|
||||
return "", "", fmt.Errorf("bloomberg credentials not configured")
|
||||
}
|
||||
|
||||
password := ""
|
||||
if cred.PasswordEncrypted != "" {
|
||||
password, err = d.enc.Decrypt(cred.PasswordEncrypted)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decrypt bloomberg password: %w", err)
|
||||
return "", "", fmt.Errorf("bloomberg credentials invalid")
|
||||
}
|
||||
}
|
||||
|
||||
b := New(d.scraperURL)
|
||||
return b.ScrapeWithCredentials(ctx, cred.Username, password, symbols)
|
||||
return cred.Username, password, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user