Compare commits
2
Commits
58791c0f97
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b04af60cf6 | ||
|
|
7b00867e2c |
No files matched your search
@@ -1,5 +1,598 @@
|
||||
# dibs
|
||||
|
||||
Personal restock watcher in Go: alerts you when an item is buyable at a fair price from a first-party seller and gets you to the cart fast.
|
||||
**dibs tells you the moment something you want is back in stock**: at a price you're happy
|
||||
with, from a seller you trust. Then it gets you to the cart as fast as possible.
|
||||
|
||||
A human always completes the purchase.
|
||||
- Works with **Amazon** out of the box: amazon.de, .co.uk, .fr, .it, .es, .nl and .com.
|
||||
- Alerts on your **desktop**, your **phone** (with the free ntfy app) or in **Discord**.
|
||||
- Other shops can be added with a small plugin file.
|
||||
- Runs on your own computer. No account to create, no server involved.
|
||||
-
|
||||
|
||||
**Contents**
|
||||
|
||||
- **Getting started**
|
||||
1. [Download](#1-download)
|
||||
2. [Set it up](#2-set-it-up)
|
||||
3. [Try it out](#3-try-it-out)
|
||||
4. [Start watching](#4-start-watching)
|
||||
5. [Alerts on your phone or in Discord](#5-alerts-on-your-phone-or-in-discord)
|
||||
6. [When a shop asks "are you human?"](#6-when-a-shop-asks-are-you-human)
|
||||
7. [Letting dibs fill your cart](#7-letting-dibs-fill-your-cart-optional)
|
||||
8. [All settings](#8-all-settings)
|
||||
|
||||
---
|
||||
|
||||
## 1. Download
|
||||
|
||||
Download the file for your operating system:
|
||||
|
||||
| Computer | File |
|
||||
|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------|
|
||||
| Windows | [dibs-windows-amd64.exe](https://git.security-command.org/Overlord/dibs/releases/download/latest/dibs-windows-amd64.exe) |
|
||||
| Mac (Apple Silicon: M1 and newer) | [dibs-darwin-arm64](https://git.security-command.org/Overlord/dibs/releases/download/latest/dibs-darwin-arm64) |
|
||||
| Linux | [dibs-linux-amd64](https://git.security-command.org/Overlord/dibs/releases/download/latest/dibs-linux-amd64) |
|
||||
|
||||
These links always give you the newest version.
|
||||
Older versions and checksums are on the [releases page](https://git.security-command.org/Overlord/dibs/releases).
|
||||
|
||||
> [!IMPORTANT]
|
||||
> dibs also needs **Google Chrome**, Chromium or Microsoft Edge for some things (see [section 6](#6-when-a-shop-asks-are-you-human)). <br>
|
||||
> If none are installed, dibs downloads a copy of Chromium by itself the first time it needs one.
|
||||
|
||||
## 2. Set it up
|
||||
|
||||
dibs is a program you run from a **terminal**, the text window where you type commands.
|
||||
|
||||
### Make a folder for dibs
|
||||
|
||||
1. Make a new folder, for example `dibs` in your Documents.
|
||||
2. Move the file you downloaded into it and rename it to `dibs` (on Windows: `dibs.exe`).
|
||||
3. Download [the example settings file](https://git.security-command.org/Overlord/dibs/raw/branch/master/examples/dibs.toml)
|
||||
into the same folder and name it `dibs.toml`.
|
||||
|
||||
> [!TIP]
|
||||
> If your browser shows the settings file as text instead of downloading it, right-click the
|
||||
> link and choose **Save Link As…**.
|
||||
|
||||
### Open a terminal in that folder
|
||||
|
||||
| Computer | How |
|
||||
|----------|-------------------------------------------------------------------------------------------------------------------------|
|
||||
| Windows | Open the folder in Explorer, right-click an empty spot and choose **Open in Terminal**. |
|
||||
| Mac | Open **Terminal** (Applications → Utilities), type `cd ` with a space, drag the folder onto the window and press Enter. |
|
||||
| Linux | Right-click in the folder and choose **Open in Terminal**. |
|
||||
|
||||
### Allow dibs to run
|
||||
|
||||
**Mac and Linux:** type these into the terminal, pressing Enter after each line:
|
||||
|
||||
```
|
||||
chmod +x dibs
|
||||
xattr -d com.apple.quarantine dibs
|
||||
```
|
||||
|
||||
The second line is only for Macs. It tells macOS that you downloaded dibs on purpose; without
|
||||
it, macOS refuses to start a program that isn't from the App Store or a registered developer.
|
||||
If it answers "No such xattr", there was nothing to allow, and that's fine.
|
||||
|
||||
**Windows:** the first start may show a blue "Windows protected your PC" box. Click
|
||||
**More info**, then **Run anyway**.
|
||||
|
||||
### Commands in this guide
|
||||
|
||||
Commands are written like this:
|
||||
|
||||
```
|
||||
dibs --config dibs.toml
|
||||
```
|
||||
|
||||
Type them as shown, but start them the way your operating system needs:
|
||||
|
||||
| OS | Type |
|
||||
|---------------|---------------------------------|
|
||||
| Windows | `.\dibs.exe --config dibs.toml` |
|
||||
| Mac and Linux | `./dibs --config dibs.toml` |
|
||||
|
||||
### Say what you want
|
||||
|
||||
Open `dibs.toml` in a text editor: Notepad on Windows, TextEdit on a Mac. It's the
|
||||
[example file](examples/dibs.toml), with an explanation next to every line. Fill in the things
|
||||
you want:
|
||||
|
||||
```toml
|
||||
[[item]]
|
||||
name = "<name>"
|
||||
shop = "amazon"
|
||||
urls = ["https://www.amazon.de/dp/<id>"]
|
||||
max_price = <price>
|
||||
currency = "EUR"
|
||||
```
|
||||
|
||||
Copy the whole `[[item]]` block for each further thing you want.
|
||||
|
||||
> [!WARNING]
|
||||
> Keep the file plain text when you save it. <br>
|
||||
> TextEdit needs **Format → Make Plain Text** first. <br>
|
||||
> In Notepad's save dialog, choose **All files**, or the file ends up as `dibs.toml.txt` and dibs won't find it.
|
||||
|
||||
Then check the file:
|
||||
|
||||
```
|
||||
dibs config validate --config dibs.toml
|
||||
```
|
||||
|
||||
It either says `OK`, or tells you the line and what's wrong with it.
|
||||
|
||||
## 3. Try it out
|
||||
|
||||
See what dibs reads from a product page:
|
||||
|
||||
```
|
||||
dibs check https://www.amazon.de/dp/<id>
|
||||
```
|
||||
|
||||
Then send yourself a test alert:
|
||||
|
||||
```
|
||||
dibs notify test --config dibs.toml
|
||||
```
|
||||
|
||||
## 4. Start watching
|
||||
|
||||
```
|
||||
dibs --config dibs.toml
|
||||
```
|
||||
|
||||
dibs shows a table with one row per product page, and a log underneath that says what it's
|
||||
doing.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Leave the window open: dibs only watches while it's running.
|
||||
|
||||
| Status | Meaning |
|
||||
|---------------|------------------------------------------------------------------------------------------------|
|
||||
| `watching` | Not available yet, or not at your price, or not from your seller. |
|
||||
| `AVAILABLE` | It can be bought now, and it matches your price and seller. |
|
||||
| `blocked` | The shop showed a bot check. dibs waits a while and tries again. |
|
||||
| `needs-human` | The shop wants a person to solve a puzzle. See [section 6](#6-when-a-shop-asks-are-you-human). |
|
||||
| `error` | Something went wrong; the log says what. |
|
||||
| `paused` | You paused it. |
|
||||
|
||||
**When an item becomes available**, its row flashes, the terminal beeps, and the alert goes out
|
||||
to every place you've set up. The alert has a link that puts the item in your cart: open it,
|
||||
check the cart, and buy.
|
||||
|
||||
After an alert, dibs stays quiet about that item for 30 minutes, unless the price drops further.
|
||||
`cooldown` in [section 8](#8-all-settings) changes how long.
|
||||
|
||||
### Keys
|
||||
|
||||
| Key | What it does |
|
||||
|-------------------------------|-----------------------------------------------------------------|
|
||||
| <kbd>↑</kbd> <kbd>↓</kbd> | Select a row |
|
||||
| <kbd>Enter</kbd> | Open the cart link of the selected item, or solve its bot check |
|
||||
| <kbd>o</kbd> | Open the product page in your browser |
|
||||
| <kbd>c</kbd> | Check the selected item now |
|
||||
| <kbd>p</kbd> | Pause or resume the selected item |
|
||||
| <kbd>Shift</kbd>+<kbd>P</kbd> | Pause or resume everything |
|
||||
| <kbd>l</kbd> | Scroll the log; press <kbd>l</kbd> again to go back |
|
||||
| <kbd>r</kbd> | Reload `dibs.toml` after you've changed it, without restarting |
|
||||
| <kbd>q</kbd> | Quit |
|
||||
|
||||
### How often dibs checks
|
||||
|
||||
Each page is checked every 3 minutes by default; `interval` changes that. Whatever the settings
|
||||
say, dibs never checks a page more than once a minute, and waits at least 10 seconds between
|
||||
any two requests to the same shop. That keeps dibs polite, and keeps shops from blocking you.
|
||||
|
||||
When a shop pushes back, dibs waits longer, up to 30 minutes, and goes back to normal once the
|
||||
shop lets it through again.
|
||||
|
||||
## 5. Alerts on your phone or in Discord
|
||||
|
||||
Desktop alerts are enabled by default.
|
||||
For alerts anywhere else, add `webhooks` under `[notify]` in `dibs.toml`.
|
||||
You can list several; dibs sends to all of them at once.
|
||||
|
||||
### On your phone, with ntfy
|
||||
|
||||
[ntfy](https://ntfy.sh) is a free app for Android and iPhone.
|
||||
|
||||
1. Install ntfy and tap **+** to subscribe to a topic. Make up a long, random topic name.
|
||||
2. Add it to `dibs.toml`:
|
||||
|
||||
```toml
|
||||
[notify]
|
||||
webhooks = [
|
||||
{ url = "https://ntfy.sh/<your-topic>", format = "ntfy" },
|
||||
]
|
||||
```
|
||||
|
||||
Tapping an alert on your phone opens the cart link.
|
||||
|
||||
> [!WARNING]
|
||||
> Anyone who knows the topic name can read your alerts, so don't pick an easy one.
|
||||
|
||||
### In Discord
|
||||
|
||||
1. In your Discord server, open **Server Settings → Integrations → Webhooks → New Webhook**,
|
||||
pick the channel and click **Copy Webhook URL**.
|
||||
2. Add it to `dibs.toml`:
|
||||
|
||||
```toml
|
||||
[notify]
|
||||
webhooks = [
|
||||
{ url = "https://discord.com/api/webhooks/<id>/<token>", format = "discord" },
|
||||
]
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> Keep the webhook address to yourself: anyone who has it can post to your channel.
|
||||
|
||||
Run `dibs notify test --config dibs.toml` to try them. For your own programs, there's also
|
||||
`format = "json"` ([the payload format](internal/notify/payload.go)).
|
||||
|
||||
## 6. When a shop asks "are you human?"
|
||||
|
||||
Shops sometimes put a check in front of their pages to keep bots out. dibs gets past most of
|
||||
them by itself, by opening the page in an invisible Chrome and waiting for the check to pass.
|
||||
|
||||
Some checks need a person, such as a puzzle. The row then shows `needs-human`, you get a desktop
|
||||
notification, and dibs leaves that shop alone for a while. To get going again:
|
||||
|
||||
1. Select the row and press <kbd>Enter</kbd>. A Chrome window opens on the page.
|
||||
2. Solve the check. The window closes by itself once the product page shows up, and dibs carries
|
||||
on.
|
||||
|
||||
Running dibs without the table (see [Running in the background](#running-in-the-background))?
|
||||
Use this instead, with the product page's address:
|
||||
|
||||
```
|
||||
dibs solve https://www.amazon.de/dp/<id>
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> dibs never uses captcha-solving services.
|
||||
|
||||
## 7. Letting dibs fill your cart (optional)
|
||||
|
||||
Normally the alert carries a link, and the item goes into your cart when you open it. dibs can
|
||||
also sign in to your shop account and put the item in your cart itself, while it's sending you
|
||||
the alert. Then you only need to open the cart and pay.
|
||||
|
||||
> [!CAUTION]
|
||||
> Shops don't like automated sign-ins! <br>
|
||||
> **Amazon in particular may lock your account**, or ask you
|
||||
> to verify it, after a sign-in it finds suspicious. <br>
|
||||
> dibs signs in as rarely as it can, and asks you to accept
|
||||
> this risk before it signs in for you the first time. <br>
|
||||
> If you'd rather not take it, don't use this mode.
|
||||
> The normal cart link works without signing in.
|
||||
|
||||
### Turn it on
|
||||
|
||||
Add this to `dibs.toml`:
|
||||
|
||||
```toml
|
||||
[accounts.amazon]
|
||||
cart_mode = "session"
|
||||
```
|
||||
|
||||
### Sign in
|
||||
|
||||
The safest way is to sign in yourself, in a Chrome window that dibs opens:
|
||||
|
||||
```
|
||||
dibs login amazon --browser --config dibs.toml
|
||||
```
|
||||
|
||||
Sign in as usual, then close the window. dibs keeps the sign-in for every Amazon site in your
|
||||
`dibs.toml`, with one window per site. When the sign-in runs out, alerts fall back to the
|
||||
normal cart link, and the log tells you to sign in again.
|
||||
|
||||
<details>
|
||||
<summary><b>Letting dibs sign in by itself</b></summary>
|
||||
|
||||
|
||||
If you'd like dibs to sign in again on its own when a sign-in runs out, it needs your email
|
||||
address and password:
|
||||
|
||||
```toml
|
||||
[accounts.amazon]
|
||||
cart_mode = "session"
|
||||
username = "<email>"
|
||||
password_env = "DIBS_AMAZON_PASS"
|
||||
twofa = true # if Amazon asks you for a code when you sign in
|
||||
```
|
||||
|
||||
Your password never goes into `dibs.toml`. `password_env` names a variable you set in the
|
||||
terminal before starting dibs, in the same window:
|
||||
|
||||
| Computer | Type |
|
||||
|---------------|----------------------------------------|
|
||||
| Windows | `$env:DIBS_AMAZON_PASS = "<password>"` |
|
||||
| Mac and Linux | `export DIBS_AMAZON_PASS='<password>'` |
|
||||
|
||||
When Amazon asks for a code, dibs shows a box where you type it in. If Amazon wants something
|
||||
dibs can't do, such as a puzzle or an approval on your phone, sign in with `--browser` instead.
|
||||
|
||||
</details>
|
||||
|
||||
### What happens when an item comes back
|
||||
|
||||
1. You get an alert straight away: **"In stock: …, adding to cart"**. <br>
|
||||
It links to the product page, not the cart link, so nothing gets added twice.
|
||||
2. dibs adds the item to your cart, unless it's there already. <br>
|
||||
This takes about half a minute, because dibs waits between requests to the shop.
|
||||
3. You get a second alert: **"In cart: …, finish checkout"**, with a link to your cart. <br>
|
||||
If adding didn't work, it says why and carries the normal cart link instead.
|
||||
|
||||
### Signing out
|
||||
|
||||
```
|
||||
dibs logout amazon --config dibs.toml
|
||||
```
|
||||
|
||||
This deletes the sign-in dibs keeps. dibs stores it encrypted, with the key in your computer's
|
||||
password store: Keychain on a Mac, Credential Manager on Windows, the desktop's keyring on
|
||||
Linux. Without a password store, dibs warns you and stores it in a file only your user account
|
||||
can read.
|
||||
|
||||
## 8. All settings
|
||||
|
||||
`dibs.toml` is a [TOML](https://toml.io) file.
|
||||
dibs rejects settings it doesn't know, so a typo can't go unnoticed.
|
||||
Anything marked optional can be left out.
|
||||
|
||||
### `[[item]]`, one per thing you want
|
||||
|
||||
| Setting | Optional | Meaning |
|
||||
|-------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `name` | No | Any name, shown in alerts. Must be different for every item. |
|
||||
| `shop` | No | The plugin that reads the pages: `amazon`, or one of yours. |
|
||||
| `urls` | No | The product pages, as a list: `["https://…", "https://…"]`. |
|
||||
| `max_price` | Yes | Only alert at this price or below. |
|
||||
| `currency` | Yes | The currency of `max_price`, such as `EUR`, `GBP` or `USD`. <br> Pages in another currency are converted at the day's exchange rate from the European Central Bank. |
|
||||
| `fx_margin` | Yes | Added to converted prices before comparing, to cover card and exchange fees: `0.05` means 5%. |
|
||||
| `seller` | Yes | `first_party` includes only offers sold by the shop itself. <br> `fulfilled` (the default) includes other sellers, if the shop ships. <br> `any` includes every seller available. |
|
||||
| `interval` | Yes | How often to check each page, such as `"90s"`, `"3m"` or `"1h"`. <br> Default `"3m"`, at least `"60s"`. |
|
||||
|
||||
### `[notify]`
|
||||
|
||||
| Setting | Meaning |
|
||||
|------------|--------------------------------------------------------------------------------------------------------------------------|
|
||||
| `desktop` | `true` (the default) or `false`: notifications on this computer. |
|
||||
| `webhooks` | Optional. Where else to send alerts, see [section 5](#5-alerts-on-your-phone-or-in-discord). |
|
||||
| `cooldown` | How long to stay quiet about an item after an alert, unless its price drops. Default `"30m"`, at most `"168h"` (a week). |
|
||||
|
||||
### `[accounts.<shop>]`, such as `[accounts.amazon]`
|
||||
|
||||
| Setting | Meaning |
|
||||
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `cart_mode` | `"deeplink"` (the default): alerts carry a cart link. `"session"`: dibs signs in and fills the cart, see [section 7](#7-letting-dibs-fill-your-cart-optional). |
|
||||
| `username` | Your email address, if dibs should sign in by itself. |
|
||||
| `password_env` | The name of the variable holding your password. dibs refuses to start if it's not set. |
|
||||
| `twofa` | `true` if signing in asks you for a code. |
|
||||
| `login_url`, `cart_url` | Optional. A different sign-in or cart page than the plugin's own. |
|
||||
|
||||
### `[plugins]`
|
||||
|
||||
Your own plugins, as `<name> = "<file>.lua"`. The path is relative to `dibs.toml`. See
|
||||
[Adding a shop](#adding-a-shop).
|
||||
|
||||
### `[sandbox]`
|
||||
|
||||
Limits for plugins. You won't need to touch these.
|
||||
|
||||
| Setting | Default | Meaning |
|
||||
|-------------------|---------|------------------------------------------------------------------------------|
|
||||
| `timeout` | `"2s"` | How long a plugin may take to read a page. |
|
||||
| `session_timeout` | `"5m"` | How long signing in or adding to the cart may take, including typing a code. |
|
||||
| `memory_mb` | `64` | Roughly how much memory one plugin call may use. |
|
||||
| `call_stack` | `200` | How deep a plugin's functions may call each other. |
|
||||
|
||||
### Without `--config`
|
||||
|
||||
If you'd rather type just `dibs`, put `dibs.toml` where dibs looks for it by default:
|
||||
|
||||
| Computer | Place |
|
||||
|----------|------------------------------------------------------------------------------|
|
||||
| Windows | `%AppData%\dibs\dibs.toml` (type `%AppData%` into Explorer's address bar) |
|
||||
| Mac | `~/Library/Application Support/dibs/dibs.toml` (Finder → Go → Go to Folder…) |
|
||||
| Linux | `~/.config/dibs/dibs.toml` |
|
||||
|
||||
dibs keeps its other files in the same folder:
|
||||
|
||||
| File | Holds |
|
||||
|----------------|-------------------------------------------------------------|
|
||||
| `state.json` | When each page was last checked, and which alerts went out. |
|
||||
| `cookies.json` | The shops' cookies. |
|
||||
| `sessions/` | Your sign-ins, encrypted. |
|
||||
|
||||
### Running in the background
|
||||
|
||||
```
|
||||
dibs --headless --config dibs.toml
|
||||
```
|
||||
|
||||
This runs without the table and writes the log to the terminal, one line per event. That's
|
||||
handy on a computer you leave running, or as a service. Codes for signing in are then asked in
|
||||
the terminal, and bot checks are solved with `dibs solve`.
|
||||
|
||||
## Adding a shop
|
||||
|
||||
A shop is added with a **plugin**: a small text file in the [Lua](https://www.lua.org) language
|
||||
that tells dibs where to find the title, the price and the "add to cart" button on the shop's
|
||||
pages. The Amazon plugin built into dibs is written the same way, and is the most complete
|
||||
example: [internal/plugin/builtin/amazon.lua](internal/plugin/builtin/amazon.lua).
|
||||
|
||||
### A first plugin
|
||||
|
||||
[examples/exampleshop.lua](examples/exampleshop.lua) is a complete plugin for a made-up shop:
|
||||
|
||||
```lua
|
||||
return {
|
||||
name = "exampleshop",
|
||||
|
||||
matches = function(url)
|
||||
return url:match("^https://www%.example%-shop%.com/") ~= nil
|
||||
end,
|
||||
|
||||
parse = function(doc, url)
|
||||
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",
|
||||
seller = "first_party",
|
||||
}
|
||||
end,
|
||||
}
|
||||
```
|
||||
|
||||
To adapt it:
|
||||
|
||||
1. Copy it next to your `dibs.toml`, and give it the shop's name, in the file name and in
|
||||
`name`.
|
||||
2. Change `matches` to the shop's address. In these patterns, `%.` stands for a dot and `%-` for
|
||||
a dash.
|
||||
3. Find the parts of a product page: in Chrome, right-click the price and choose **Inspect**. The
|
||||
highlighted line shows the element, such as `<span class="product-price">`; its selector is
|
||||
`.product-price`. Do the same for the title, the button and the stock text.
|
||||
4. List the plugin in `dibs.toml`, and use its name as the items' `shop`:
|
||||
|
||||
```toml
|
||||
[plugins]
|
||||
exampleshop = "exampleshop.lua"
|
||||
```
|
||||
|
||||
5. Try it on a real page:
|
||||
|
||||
```
|
||||
dibs check https://www.example-shop.com/p/<id> --config dibs.toml
|
||||
```
|
||||
|
||||
A plugin of yours with the same name as a built-in one replaces it.
|
||||
|
||||
### What a plugin can do
|
||||
|
||||
<details>
|
||||
<summary><b>The plugin table</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
A plugin returns a table with these entries. Only `parse` is required.
|
||||
|
||||
| Entry | Meaning |
|
||||
|-------------------------|----------------------------------------------------------------------------------|
|
||||
| `name` | The plugin's name. |
|
||||
| `matches(url)` | Returns `true` for URLs the plugin reads. Lets `dibs check` pick the plugin. |
|
||||
| `normalize(url)` | Returns the URL in one standard form, so the same product isn't watched twice. |
|
||||
| `parse(doc, url)` | Reads a page and returns what it found (see below). |
|
||||
| `cart_link(url, id)` | Returns a link that puts the item in the cart. `id` is the `id` from `parse`. |
|
||||
| `login(ctx, account)` | Signs in, for [session mode](#7-letting-dibs-fill-your-cart-optional). |
|
||||
| `add_to_cart(ctx, url)` | Puts the item in the cart, for session mode. |
|
||||
| `session_warning` | Text shown once before the first sign-in, such as a warning about account locks. |
|
||||
|
||||
`parse` returns a table with:
|
||||
|
||||
| Field | Meaning |
|
||||
|-------------|-------------------------------------------------------------------------------|
|
||||
| `available` | Required. `true` if the item can be bought now. |
|
||||
| `title` | The product's name. |
|
||||
| `price` | A number, such as `129.99`. |
|
||||
| `currency` | A code such as `"EUR"`. |
|
||||
| `seller` | `"first_party"`, `"fulfilled"`, `"third_party"` or `"unknown"` (the default). |
|
||||
| `id` | The shop's product number, passed to `cart_link`. |
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Reading the page</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
`doc` is the page. Each of its methods takes a CSS selector and works on the first element that
|
||||
matches; without a selector, on the element itself:
|
||||
|
||||
| Method | Returns |
|
||||
|-----------------------|---------------------------------------------------------------------------|
|
||||
| `doc:text(sel)` | The visible text, with spaces tidied up, or `nil` if there's none. |
|
||||
| `doc:attr(sel, name)` | The value of an attribute, such as `doc:attr("a.buy", "href")`, or `nil`. |
|
||||
| `doc:exists(sel)` | Whether anything matches. |
|
||||
| `doc:count(sel)` | How many elements match. |
|
||||
| `doc:html(sel)` | The element's HTML, or `nil`. |
|
||||
| `doc:all(sel)` | A list of every matching element, each with the same methods. |
|
||||
|
||||
Helpers:
|
||||
|
||||
| Helper | Does |
|
||||
|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `parse_price(text)` | Reads a price such as `"1.299,99 €"`, `"£1,299.99"` or `"1 299,99 €"`. Returns the number and the currency code (or `nil`), or `nil` if the text has no price. |
|
||||
| `contains_any(text, {…})` | Whether the text contains any of the phrases, ignoring upper and lower case. |
|
||||
| `regex_match(text, pattern)` | Matches a [Go regular expression](https://pkg.go.dev/regexp/syntax). Returns a list of the captured groups (or of the whole match), or `nil`. |
|
||||
| `log(…)` | Writes a line to dibs's log. |
|
||||
|
||||
Plugins run in a sandbox: they can't read or write files, run programs, or reach the network
|
||||
other than through `ctx`. Each call is stopped after a time limit and a rough memory limit (see
|
||||
`[sandbox]` in [section 8](#8-all-settings)).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Session mode in a plugin</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
`login(ctx, account)` and `add_to_cart(ctx, url)` get a `ctx` to talk to the shop with the
|
||||
account's cookies. Like checks, requests through `ctx` wait at least 10 seconds after the last
|
||||
request to the same shop.
|
||||
|
||||
| Call | Does |
|
||||
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `ctx:get(url, opts)` | Loads a page. |
|
||||
| `ctx:post(url, opts)` | Sends a form. `opts.form` is a table of fields; `opts.body` and `opts.content_type` send anything else. |
|
||||
| `ctx:click(url, sel)` | Opens the page in an invisible Chrome, clicks the element and returns the page the click leads to. For shops that only accept what their own page scripts send, as Amazon does with "add to cart". |
|
||||
| `ctx:prompt(label, secret)` | Asks the user, such as for a code. `secret = true` hides the typing. |
|
||||
| `ctx:cookies(url)` | The account's cookies for the URL, as a table of names and values. |
|
||||
| `ctx.account` | `username`, `site`, `twofa`, `login_url` and `cart_url`, without the password. |
|
||||
|
||||
`opts` may also have `referer` (the page the request comes from) and `headers` (a table).
|
||||
Every call returns the page as a table with `status`, `url` (after redirects), `verdict`
|
||||
(`"ok"`, `"not-found"`, `"challenge"`, `"blocked"`, `"http-error"` or `"needs-human"`), `body`,
|
||||
`headers` (with lower-case names) and `doc`.
|
||||
|
||||
`login` gets `account` with the `password` as well, and signs in to `account.site`. When it
|
||||
can't, it stops with `error("…")`, and the message shows up in the log.
|
||||
|
||||
`add_to_cart` must not add the item if it's in the cart already. It returns `true` and the cart
|
||||
page's URL once the item is in the cart, or `false` if it finds the session signed out, in which
|
||||
case dibs signs in again.
|
||||
|
||||
</details>
|
||||
|
||||
## For developers
|
||||
|
||||
dibs is written in Go and needs Go 1.26 or newer. It builds without cgo into a single file.
|
||||
|
||||
```
|
||||
make build # builds ./dibs for this computer
|
||||
make test # runs the tests; GOTESTFLAGS=-short skips the ones that start Chrome
|
||||
make lint # runs golangci-lint at a pinned version
|
||||
make release # builds the release binaries into dist/, with SHA256SUMS
|
||||
```
|
||||
|
||||
`make release TARGETS="linux/arm64 darwin/amd64"` builds for other systems, such as Intel Macs.
|
||||
|
||||
The Amazon plugin's tests also run on real product pages, which aren't kept in the repository
|
||||
because they change and may contain personal data. `dibs fixtures` downloads the pages listed in
|
||||
[testdata/amazon/cases.toml](testdata/amazon/cases.toml); without them, those tests are skipped.
|
||||
|
||||
## License
|
||||
|
||||
[GNU Affero General Public License v3.0](LICENSE).
|
||||
@@ -0,0 +1,79 @@
|
||||
# An example dibs.toml. Lines starting with # are comments; dibs ignores them.
|
||||
#
|
||||
# Replace everything in <angle brackets> with your own, such as <id> with the
|
||||
# product number from an Amazon address (https://www.amazon.de/dp/B0HMX2FSTF
|
||||
# has the id B0HMX2FSTF). `dibs config validate --config dibs.toml` checks the
|
||||
# file for you.
|
||||
|
||||
|
||||
# ── What to watch ────────────────────────────────────────────────────────────
|
||||
#
|
||||
# Each [[item]] block is one thing you want. It can have several URLs, such as
|
||||
# the same product on different Amazon sites. dibs alerts you when any of
|
||||
# them can be bought.
|
||||
|
||||
[[item]]
|
||||
name = "<name>" # any name you like; it shows up in alerts
|
||||
shop = "amazon" # which plugin reads the page; amazon is built in
|
||||
urls = [ # the product pages
|
||||
"https://www.amazon.de/dp/<id>",
|
||||
"https://www.amazon.co.uk/dp/<id>",
|
||||
]
|
||||
max_price = 129.99 # optional: only alert at this price or below
|
||||
currency = "EUR" # optional: the currency of max_price; other
|
||||
# currencies are converted at the day's rate
|
||||
fx_margin = 0.05 # optional: add 5% to converted prices, for
|
||||
# card fees, before comparing with max_price
|
||||
seller = "fulfilled" # "first_party": sold by Amazon itself
|
||||
# "fulfilled": also other sellers, if Amazon ships (the default)
|
||||
# "any": every seller
|
||||
interval = "3m" # how often to check each URL; at least "60s"
|
||||
|
||||
# A second item only needs a name, a shop and a URL. Remove the # in front of
|
||||
# each line to use it:
|
||||
#
|
||||
# [[item]]
|
||||
# name = "<another name>"
|
||||
# shop = "amazon"
|
||||
# urls = ["https://www.amazon.de/dp/<another id>"]
|
||||
|
||||
|
||||
# ── How to tell you ──────────────────────────────────────────────────────────
|
||||
|
||||
[notify]
|
||||
desktop = true # a notification on this computer (the default)
|
||||
cooldown = "30m" # after an alert, stay quiet about the item for
|
||||
# this long, unless the price drops
|
||||
|
||||
# Alerts on your phone or in Discord. Remove the # in front of the lines you
|
||||
# want; the README explains where to get the addresses.
|
||||
#
|
||||
# webhooks = [
|
||||
# { url = "https://ntfy.sh/<your-topic>", format = "ntfy" },
|
||||
# { url = "https://discord.com/api/webhooks/<id>/<token>", format = "discord" },
|
||||
# ]
|
||||
|
||||
|
||||
# ── Your shop account (optional) ─────────────────────────────────────────────
|
||||
#
|
||||
# Without this, alerts carry a link that puts the item in your cart when you
|
||||
# open it. With cart_mode = "session", dibs signs in to your account and puts
|
||||
# the item in the cart itself. Read about the risks in the README first.
|
||||
#
|
||||
# [accounts.amazon]
|
||||
# cart_mode = "session"
|
||||
#
|
||||
# Only if dibs should sign in by itself, rather than you with
|
||||
# `dibs login amazon --browser`:
|
||||
#
|
||||
# username = "<email>"
|
||||
# password_env = "DIBS_AMAZON_PASS" # the variable holding your password
|
||||
# twofa = true # if Amazon asks you for a code
|
||||
|
||||
|
||||
# ── Your own plugins (optional) ──────────────────────────────────────────────
|
||||
#
|
||||
# For shops dibs has no plugin for. The path is relative to this file.
|
||||
#
|
||||
# [plugins]
|
||||
# <name> = "<name>.lua"
|
||||
@@ -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