feat: Add limited cdiscount.com support (#31)
- Only the first products are parsed - Notifications not sent because only available products are listed and the very first discovery doesn't send a notification to avoid false positives - Products stay available forever unless there is a retention period configured because unavailable products are not listed Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
2c0b972849
commit
d0d606419f
1 changed files with 37 additions and 0 deletions
|
@ -80,6 +80,8 @@ func createQuery(shopName string, url string) (string, error) {
|
|||
switch shopName {
|
||||
case "cybertek.fr":
|
||||
return createQueryForCybertek(url), nil
|
||||
case "cdiscount.com":
|
||||
return createQueryForCdiscount(url), nil
|
||||
case "ldlc.com":
|
||||
return createQueryForLDLC(url), nil
|
||||
case "materiel.net":
|
||||
|
@ -459,3 +461,38 @@ FOR el IN ELEMENTS(doc, "div.vs-product-list div.vs-product-list-item")
|
|||
`
|
||||
return q
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* - list next products by triggering browser events and wait for them to load
|
||||
* - list unavailable products
|
||||
* - add pagination
|
||||
*/
|
||||
func createQueryForCdiscount(url string) string {
|
||||
q := `
|
||||
LET page = '` + url + `'
|
||||
LET doc = DOCUMENT(page, {driver: "cdp"})
|
||||
|
||||
WAIT_ELEMENT(doc, '.lpMain')
|
||||
WAIT_ELEMENT(doc, '#pager')
|
||||
|
||||
LET main = ELEMENT(doc, '.lpMain')
|
||||
|
||||
FOR product IN ELEMENTS(main, '.lpTdgProduct')
|
||||
// remove "carte graphique" and product identifier from name
|
||||
LET title = REGEX_REPLACE(ELEMENT(product, '.prdtBILTit'), '(?i)carte graphique | \(.*\)', '')
|
||||
LET a = ELEMENT(product, '.prdtBILA')
|
||||
LET price = TO_FLOAT(REGEX_REPLACE(INNER_TEXT(ELEMENT(product, '.prdtBILPrice .price')), '€', '.'))
|
||||
LET price_currency = 'EUR'
|
||||
LET available = ELEMENT_EXISTS(product, '.btGreen')
|
||||
RETURN {
|
||||
'name': title,
|
||||
'url': a.attributes.href,
|
||||
'price': price,
|
||||
'price_currency': price_currency,
|
||||
'available': available
|
||||
}
|
||||
)
|
||||
`
|
||||
return q
|
||||
}
|
||||
|
|
Reference in a new issue