Update README and add examples: dibs.toml and custom plugin template.
This commit is contained in:
1 parent
58791c0f97
commit
7b00867e2c
3 files changed
+714
-2
No files matched your search
@@ -0,0 +1,39 @@
|
||||
-- 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,
|
||||
}
|
||||
Reference in new issue
Block a user