Compare commits

..

5 commits

Author SHA1 Message Date
f4159bc30d debug log
Some checks are pending
Docker build and publish / build-and-push-image (push) Waiting to run
2026-01-03 21:59:20 +00:00
b57546140b remove unused compose file 2026-01-03 21:59:09 +00:00
de8af89d71 add item specification (details), if available 2025-07-22 22:18:05 +00:00
a31e490dcb add a super simple compose.yml for convenience 2025-07-21 21:15:57 +00:00
1838e35b78 allow to choose a list by UUID 2025-07-21 21:15:28 +00:00
4 changed files with 89 additions and 5 deletions

View file

@ -1,3 +1,4 @@
EMAIL=email
PASSWORD=password
#LIST_UUID=optional list uuid
WEBHOOK_URL=trmnl webhook url

View file

@ -36,7 +36,8 @@ You can either run the backend service through docker or run the script directly
#### Docker
Pull the docker image and pass the email, password and webhook url as env variables.
Pull the docker image and pass the email, password and webhook url as env variables.<br/>
You can also provide an optional list UUID (see 3. below).
```bash
docker pull ghcr.io/yshrdbrn/trmnl-bring-plugin:main
@ -47,15 +48,44 @@ docker run
-e 'EMAIL'='<email>'
-e 'PASSWORD'='<password>'
-e 'WEBHOOK_URL'='<url>'
-e 'LIST_UUID'='<list UUID>' # optional
'ghcr.io/yshrdbrn/trmnl-bring-plugin:main'
```
#### Run the script directly
Clone the repo and rename `.env.example` to `.env` and put in your email, password and webhook url there. Then run the script:
Clone the repo and rename `.env.example` to `.env` and put in your email, password, webhook url, and optionally list UUID there. Then run the script:
```bash
python3 -m venv venv
pip install -r requirements.txt
python ./main.py
```
### 3. Optional: Determine your list UUID and provide it to the plugin
You can manage several shopping lists on Bring with the same account.<br/>
If you want to choose a specific list, you need to determine its UUID. Otherwise the plugin just uses the first list it encounters (which might not be the first list you see in the app or web page).
```bash
docker run
-e 'EMAIL'='<email>'
-e 'PASSWORD'='<password>'
'ghcr.io/yshrdbrn/trmnl-bring-plugin:main'
python -u ./fetch_lists.py
```
Or run it without docker (EMAIL and PASSWORD must be set in .env and dependencies installed as in 2. above):
```bash
python ./fetch_lists.py
```
You should get a list of lists like this:
| **Name** | **UUID** |
| --------- | ------------------------------- |
| Groceries | 12345678-90ab-cdef-0123456789ab |
| Stuff | abcdef01-2345-6789-0123456789ab |
Copy the UUID of the list you would like to display, and set it as `LIST_UUID` either via `-e` in docker or in the `.env` file. Restart your plugin service to apply the change.

36
fetch_lists.py Normal file
View file

@ -0,0 +1,36 @@
import asyncio
import os
import aiohttp
from bring_api import Bring
from dotenv import load_dotenv
load_dotenv()
class Color:
BOLD = '\033[1m'
END = '\033[0m'
async def main():
email = os.getenv("EMAIL")
password = os.getenv("PASSWORD")
async with aiohttp.ClientSession() as session:
bring = Bring(session, email, password)
await bring.login()
lists = (await bring.load_lists()).lists
if len(lists) <= 0:
print("No lists found on account")
return
name_col_width = max(len("Name"), max(len(l.name) for l in lists)) + 2 # padding
uuid_col_width = max(len("UUID"), max(len(l.listUuid) for l in lists))
print(f"{Color.BOLD}{'Name'.ljust(name_col_width)} {'UUID'.ljust(uuid_col_width)}{Color.END}")
for l in lists:
print(f"{l.name.ljust(name_col_width)} {l.listUuid.ljust(uuid_col_width)}")
if __name__ == "__main__":
asyncio.run(main())

21
main.py
View file

@ -47,17 +47,25 @@ class BringPlugin:
def __init__(self):
self.email = os.getenv("EMAIL")
self.password = os.getenv("PASSWORD")
self.list_uuid = os.getenv("LIST_UUID")
self.webhook_url = os.getenv("WEBHOOK_URL")
self.bring = None
self.existing_list = None
print(f"email: {self.email}")
async def grab_items(self, bring_list):
"""Grabs the items of the list using the list's uuid"""
item_objs = (await self.bring.get_list(bring_list.uuid)).items.purchase
bring_list.items = [item.itemId for item in item_objs]
bring_list.items = [self.transform_item(item) for item in item_objs]
print(f"Successfully fetched items at {datetime.datetime.now().isoformat()}")
print(f"Items = {bring_list.items}")
def transform_item(self, api_item):
if api_item.specification:
return f"{api_item.itemId} ({api_item.specification})"
else:
return api_item.itemId
async def send_list_to_trmnl(self, session, bring_list):
"""Sends the list to TRMNL if it has changed"""
if self.existing_list == bring_list:
@ -95,7 +103,16 @@ class BringPlugin:
if self.existing_list:
new_list = copy.deepcopy(self.existing_list)
else:
bring_api_list = (await self.bring.load_lists()).lists[0]
all_api_lists = (await self.bring.load_lists()).lists
if self.list_uuid is None:
if len(all_api_lists) > 1:
print(f"LIST_UUID not specified, will use first list.")
bring_api_list = all_api_lists[0]
else:
bring_api_list = next((l for l in all_api_lists if l.listUuid == self.list_uuid), None)
if bring_api_list is None:
print(f"No list with UUID \"{self.list_uuid}\" found, will use first list instead.")
bring_api_list = all_api_lists[0]
new_list = BringList(name=bring_api_list.name, uuid=bring_api_list.listUuid)
await self.grab_items(new_list)