Files
dibs/examples/exampleshop.lua

40 lines
1.2 KiB
Lua

-- An example plugin for a made-up shop at www.example-shop.com.
--
-- To watch a shop dibs has no plugin for, copy this file next to your
-- dibs.toml, change the name and the CSS selectors to fit the shop's product
-- pages, and list it in dibs.toml:
--
-- [plugins]
-- exampleshop = "exampleshop.lua"
--
-- Then try it on a real product page with:
--
-- dibs check https://www.example-shop.com/p/12345
return {
-- The name items use as `shop = "exampleshop"`.
name = "exampleshop",
-- Which URLs this plugin is for.
matches = function(url)
return url:match("^https://www%.example%-shop%.com/") ~= nil
end,
-- Reads a product page. doc is the page, url is its address.
parse = function(doc, url)
-- parse_price understands "1.299,99 €", "£1,299.99" and the like.
local price, currency = parse_price(doc:text(".product-price"))
local sold_out = contains_any(doc:text(".stock-status"), { "sold out", "ausverkauft", "épuisé" })
return {
title = doc:text("h1"),
available = doc:exists("button.add-to-cart") and not sold_out,
price = price,
currency = currency or "EUR",
-- The shop sells everything itself, so no seller needs checking.
seller = "first_party",
}
end,
}