Some checks failed
dev test / test (push) Successful in 1m20s
dev test / vulnCheck (push) Successful in 32s
dev test / Ci-Lint (push) Successful in 28s
${{ github.actor }} executed Build Push Prod / build (push) Failing after 37s
${{ github.actor }} executed Build Push Prod / deploy (push) Has been skipped
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package crawler
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"git.maximotejeda.com/maximo/us_dop_scrapper/config"
|
|
"git.maximotejeda.com/maximo/us_dop_scrapper/helpers"
|
|
"git.maximotejeda.com/maximo/us_dop_scrapper/internal/application/core/domain"
|
|
"git.maximotejeda.com/maximo/us_dop_scrapper/internal/ports"
|
|
"github.com/playwright-community/playwright-go"
|
|
)
|
|
|
|
type bcd struct{}
|
|
|
|
func NewBCD() ports.APIPorts {
|
|
return &bcd{}
|
|
}
|
|
|
|
func (b bcd) Scrape(ctx context.Context, page playwright.Page, log *slog.Logger) (insts []*domain.History, err error) {
|
|
log = log.With("scrapper", "bcd")
|
|
tout := 90000.00
|
|
if _, err = page.Goto(config.GetBCDURL(), playwright.PageGotoOptions{
|
|
Timeout: &tout,
|
|
WaitUntil: playwright.WaitUntilStateLoad,
|
|
}); err != nil {
|
|
log.Error("could not get info", "error", err)
|
|
return nil, err
|
|
}
|
|
compraLocator := page.Locator("span#actualPurchaseValue")
|
|
|
|
_ = compraLocator.WaitFor(playwright.LocatorWaitForOptions{
|
|
Timeout: &tout,
|
|
State: playwright.WaitForSelectorStateVisible,
|
|
})
|
|
|
|
ventaLocator := page.Locator("span#actualSellingValue")
|
|
|
|
compra, err := compraLocator.TextContent()
|
|
if err != nil {
|
|
log.Error("locating compra", "err", err)
|
|
return nil, err
|
|
}
|
|
venta, err := ventaLocator.TextContent()
|
|
if err != nil {
|
|
log.Error("locating venta", "err", err)
|
|
return nil, err
|
|
}
|
|
|
|
inst := &domain.History{
|
|
Parser: "bcd",
|
|
Name: "banco central dominicano",
|
|
Parsed: time.Now().Unix(),
|
|
}
|
|
|
|
inst.Compra = helpers.Normalize(compra)
|
|
inst.Venta = helpers.Normalize(venta)
|
|
|
|
if inst.Compra == 0 || inst.Venta == 0 {
|
|
return nil, fmt.Errorf("bcd: institution not parsed compra or venta cant be 0")
|
|
}
|
|
return []*domain.History{inst}, nil
|
|
}
|