Skip to content

Commit b388de5

Browse files
Updates for config file parsing
1 parent ca8fa37 commit b388de5

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ output.xml
55
report.html
66
credentials
77
testme.py
8+
__pycache__

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# robotframework-apprise
2-
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
2+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
33

44
```robotframework-apprise``` is a [Robot Framework](https://www.robotframework.org) keyword collection for the [Apprise](https://github.com/caronc/apprise) push message library. It enables Robot Framework users to send push/email messages to every message service supported by Apprise.
55

@@ -28,12 +28,15 @@ In order to run the example code, you need to provide at least one valid target
2828
|``Set Delimiter``|Optional reconfiguration of this Robot Framework library's delimiter. See details below|
2929
|``Set Notify Type``|Sets one of Apprise's [supported notify types](https://github.com/caronc/apprise/wiki/Development_API#message-types-and-themes). Valid values are ``info``,``success``,``warning``, and ``failure``. Default notify type is ``info``|
3030
|``Set Body Format``|Sets one of Apprise's [supported body formats](https://github.com/caronc/apprise/wiki/Development_API#notify--send-notifications). Valid values are ``html``,``text``, and ``markdown``. Default body format is ``html``|
31+
|``Set Config File``|Allows you to specify a single Apprise [config file](https://github.com/caronc/apprise#configuration-files) in YAML or Text format |
3132

3233

3334
All ``clients`` and ``attachments`` options can be passed as a ``List`` type variable or as a ``string``. If you use a ``string``, the default delimiter is a comma ``,``. In case you need to use a different delimiter for your string, use the ``Set Delimiter`` keyword.
3435

3536
All ``Set ...`` keywords provide corresponding ``Get ...`` keywords.
3637

38+
If you specify ``Client`` settings additionally to a ``Config File``, the library will honor both settings.
39+
3740
``Attachments`` are purely optional. Providing at least one ``Client`` is mandatory, though. Both ``Attachments`` and ``Clients`` can either be provided as a ``List`` item or as a separated string.
3841

3942
Examples:
@@ -55,7 +58,14 @@ Set Delimiter ^
5558
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! clients=<apprise_client> attachments=http://www.mysite.com/image1.jpg^http://www.mysite.com/image2.jpg
5659
```
5760

61+
```robot
62+
# Send a message with one client and a List which contains our images
63+
@{IMAGE_LIST}= Create List http://www.mysite.com/image1.jpg http://www.mysite.com/image2.jpg
64+
${CONFIG_FILE} config.yaml
65+
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! config_file=${CONFIG_FILE} attachments=${IMAGE_LIST}
66+
```
67+
68+
5869
## Known issues
5970

60-
- This library uses Apprise's default async behavior. Currently, you cannot send messages in a synchronous way.
61-
- The current version of this library does not support Apprise's whole feature set. Options such as tagging are not implemented.
71+
- The current version of this library does not support Apprise's whole feature set. Options such as tagging are not implemented (but may work if you use a [config file](https://github.com/caronc/apprise#configuration-files)-based setting)

src/AppriseLibrary.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333
logger = logging.getLogger(__name__)
3434

35-
__version__ = "0.1.0"
35+
__version__ = "0.2.0"
3636
__author__ = "Joerg Schultze-Lutter"
3737

3838

@@ -393,8 +393,12 @@ def send_apprise_message(
393393

394394
# Now check if we need to create the Apprise config object
395395
if self.config_file and self.config_file != "":
396+
# Does the file exist?
396397
if os.path.isfile(self.config_file):
397-
_apprise_config = self.apprise_instance.AppriseConfig()
398+
# File exists; create the config object and then
399+
# add the config file to the config object
400+
_apprise_config = apprise.AppriseConfig()
401+
_apprise_config.add(self.config_file)
398402
else:
399403
logger.debug(
400404
msg=f"Config file '{self.config_file}' does not exist; ignoring config file reference"
@@ -422,11 +426,13 @@ def send_apprise_message(
422426
self.body_format = self.__transform_body_format(body_format=body_format)
423427

424428
# Check if we have received at least one client
425-
if len(self.clients) < 1 and not apprise_config:
426-
raise ValueError("You need to specify at least one target client")
429+
if (self.clients and len(self.clients) < 1) and not _apprise_config:
430+
raise ValueError(
431+
"You need to specify at least one target client or an Apprise config file"
432+
)
427433

428-
# Attach the clients
429-
# If we have no config file, then add the clients directly
434+
# Process our single client URLs
435+
# If we have no config file/object , add the clients directly to Apprise
430436
# otherwise, add the config data to the config object and
431437
# later on add the config object to Apprise
432438
for client in self.clients:

src/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 1
2+
3+
urls:
4+
# One-liner (no colon at the end); just the url as you'd expect it:
5+
- tgram://MY_CREDENTIALS_GO_HERE
6+

src/send_apprise_message.robot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Library AppriseLibrary.py
88
*** Variables ***
99
@{IMAGE_LIST} https://miro.medium.com/max/553/1*wnMQPTmEsIq0TiRgfX4hig.png https://raw.githubusercontent.com/caronc/apprise/master/apprise/assets/themes/default/apprise-logo.png
1010
${CLIENT} CONFIGURE_THIS_SETTING_WITH_AT_LEAST_ONE_VALID_APPRISE_ACCOUNT
11+
${CONFIG_FILE} config.yaml
1112

1213
*** Test Cases ***
1314
Send Message Through Apprise
1415
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! clients=${CLIENT} attachments=${IMAGE_LIST}
16+
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! config_file=${CONFIG_FILE} attachments=${IMAGE_LIST}

0 commit comments

Comments
 (0)