Archived
1
0
Fork 0

Add STEG support (#10)

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-03-16 15:29:28 +01:00
parent 77230bd0a4
commit 42b8f50068
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7

View file

@ -137,6 +137,8 @@ func createQuery(shopName string, url string) (string, error) {
return createQueryForMediamarktCh(url), nil
case "newegg.com":
return createQueryForNewegg(url), nil
case "steg-electronics.ch":
return createQueryForStegElectronics(url), nil
case "topachat.com":
return createQueryForTopachat(url), nil
default:
@ -428,3 +430,40 @@ RETURN FLATTEN(results)
`
return q
}
func createQueryForStegElectronics(url string) string {
q := `
LET first_page = '` + url + `'
LET doc = DOCUMENT(first_page, { driver: "cdp" })
LET next_pages = (
FOR next_page IN ELEMENTS(doc, "div#pagination a.current-pages")
RETURN next_page.attributes.href
)
LET pages = SORTED_UNIQUE(APPEND(REMOVE_VALUE(next_pages, '#'), first_page))
LET results = (
FOR page IN pages
NAVIGATE(doc, page)
LET products = (
FOR el IN ELEMENTS(doc, "article.product-list-container div.productGridElement")
LET link = ELEMENT(el, "h2 a")
LET shipment = ELEMENT(el, "div.availabilityInfo a .iconShipment").attributes.style.color != "#BFBFBF"
LET pickup = ELEMENT(el, "div.availabilityInfo a .iconPickup").attributes.style.color != "#BFBFBF"
LET price = TO_FLOAT(SUBSTITUTE(INNER_TEXT(ELEMENT(el, "div.generalPrice")), "'", ""))
RETURN {
name: link.attributes.title,
url: link.attributes.href,
available: shipment OR pickup,
price: price,
price_currency: "CHF",
}
)
RETURN products
)
RETURN FLATTEN(results)
`
return q
}