Compare commits
No commits in common. "f4159bc30d5cdab449093d8a449359845d1c7777" and "4a6d2ff96d552aa8d1ff316ab35ac4d46d83d38d" have entirely different histories.
f4159bc30d
...
4a6d2ff96d
4 changed files with 5 additions and 89 deletions
|
|
@ -1,4 +1,3 @@
|
|||
EMAIL=email
|
||||
PASSWORD=password
|
||||
#LIST_UUID=optional list uuid
|
||||
WEBHOOK_URL=trmnl webhook url
|
||||
WEBHOOK_URL=trmnl webhook url
|
||||
34
README.md
34
README.md
|
|
@ -36,8 +36,7 @@ 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.<br/>
|
||||
You can also provide an optional list UUID (see 3. below).
|
||||
Pull the docker image and pass the email, password and webhook url as env variables.
|
||||
|
||||
```bash
|
||||
docker pull ghcr.io/yshrdbrn/trmnl-bring-plugin:main
|
||||
|
|
@ -48,44 +47,15 @@ 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, webhook url, and optionally list UUID there. Then run the script:
|
||||
Clone the repo and rename `.env.example` to `.env` and put in your email, password and webhook url 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.
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
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
21
main.py
|
|
@ -47,25 +47,17 @@ 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 = [self.transform_item(item) for item in item_objs]
|
||||
bring_list.items = [item.itemId 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:
|
||||
|
|
@ -103,16 +95,7 @@ class BringPlugin:
|
|||
if self.existing_list:
|
||||
new_list = copy.deepcopy(self.existing_list)
|
||||
else:
|
||||
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]
|
||||
bring_api_list = (await self.bring.load_lists()).lists[0]
|
||||
new_list = BringList(name=bring_api_list.name, uuid=bring_api_list.listUuid)
|
||||
|
||||
await self.grab_items(new_list)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue