trading_agent.terminal.attachment_opener
¶
Downloads a file the desk sent, or a picture a tool showed it, and opens it with the desktop's default program.
Files are saved under the state folder's "downloads" folder and opened with xdg-open, so a picture opens in the image viewer and a PDF in the PDF reader, as a new browser tab does on the web page.
Typical usage example:
opener = AttachmentOpener(gateway) path = await opener.open_attachment('general', attachment)
AttachmentOpener
¶
Saves desk files locally and opens them.
Creates the opener.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gateway
|
GatewayClient
|
The gateway, to download from. |
required |
folder
|
Path | None
|
Where to save files, or None for the state folder's "downloads" folder. |
None
|
Source code in src/trading_agent/terminal/attachment_opener.py
save_attachment
async
¶
Downloads an attachment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk it belongs to. |
required |
attachment
|
dict[str, Any]
|
The attachment, with attachment_id and file_name. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Where it was saved. |
Raises:
| Type | Description |
|---|---|
GatewayError
|
The gateway could not send it. |
OSError
|
The file could not be written. |
Source code in src/trading_agent/terminal/attachment_opener.py
save_picture
async
¶
Downloads a picture from inside a desk's folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
picture_path
|
str
|
The picture's path relative to the desk folder. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Where it was saved. |
Raises:
| Type | Description |
|---|---|
GatewayError
|
The gateway could not send it. |
OSError
|
The file could not be written. |
Source code in src/trading_agent/terminal/attachment_opener.py
open
¶
Opens a saved file with the desktop's default program, without waiting for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when xdg-open was started, False when it is not installed. |