allow to choose a list by UUID

This commit is contained in:
Lysann Tranvouez 2025-07-21 21:15:28 +00:00
parent 4a6d2ff96d
commit 1838e35b78
4 changed files with 81 additions and 4 deletions

View file

@ -1,3 +1,4 @@
EMAIL=email EMAIL=email
PASSWORD=password PASSWORD=password
#LIST_UUID=optional list uuid
WEBHOOK_URL=trmnl webhook url 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 #### 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 ```bash
docker pull ghcr.io/yshrdbrn/trmnl-bring-plugin:main docker pull ghcr.io/yshrdbrn/trmnl-bring-plugin:main
@ -47,15 +48,44 @@ docker run
-e 'EMAIL'='<email>' -e 'EMAIL'='<email>'
-e 'PASSWORD'='<password>' -e 'PASSWORD'='<password>'
-e 'WEBHOOK_URL'='<url>' -e 'WEBHOOK_URL'='<url>'
-e 'LIST_UUID'='<list UUID>' # optional
'ghcr.io/yshrdbrn/trmnl-bring-plugin:main' 'ghcr.io/yshrdbrn/trmnl-bring-plugin:main'
``` ```
#### Run the script directly #### 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 ```bash
python3 -m venv venv python3 -m venv venv
pip install -r requirements.txt pip install -r requirements.txt
python ./main.py 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())

12
main.py
View file

@ -47,6 +47,7 @@ class BringPlugin:
def __init__(self): def __init__(self):
self.email = os.getenv("EMAIL") self.email = os.getenv("EMAIL")
self.password = os.getenv("PASSWORD") self.password = os.getenv("PASSWORD")
self.list_uuid = os.getenv("LIST_UUID")
self.webhook_url = os.getenv("WEBHOOK_URL") self.webhook_url = os.getenv("WEBHOOK_URL")
self.bring = None self.bring = None
self.existing_list = None self.existing_list = None
@ -95,7 +96,16 @@ class BringPlugin:
if self.existing_list: if self.existing_list:
new_list = copy.deepcopy(self.existing_list) new_list = copy.deepcopy(self.existing_list)
else: 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) new_list = BringList(name=bring_api_list.name, uuid=bring_api_list.listUuid)
await self.grab_items(new_list) await self.grab_items(new_list)