Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The full notification can be passed in the command by using the keyword ${json} that will translate the structure in a JSON inline string. Finally, the trigger can save the notification to a JSON file whose file name can be retrieved using the keyword ${jsonpath}.

...

Aviso as a Python API

Aviso can be used as a Python API. This is intended for user users that wants want to integrate Aviso in a bigger workflow written in Python or that simply have their trigger defined as a Python function. Below an example of a python script that defines a function to be executed once a notification is received, creates a listener that references to this function trigger and finally passes it to aviso to execute.

The listening will happen in a background thread defined as daemon therefore it is responsibility of the user to keep the main thread alive.

Please note that the user configuration has not been defined in this example, the system will automatically read the configuration file defined above.Aviso configuration file /etc/aviso/config.yaml is still needed for the authentication as explained above.

Code Block
languagepy
from pyaviso import NotificationManager

# define function to be called
def do_something(notification):
    # do something with the notification
    ...

# define the trigger
trigger = {"type": "function", "function": do_something}

# create a event listener request that uses that trigger
request = {"destination": "FOO", "stream": "enfo", "date": 20190810, "time": 0}
listener = {"event": "dissemination", "request": request, "triggers": [trigger]}
listeners = {"listeners": [listener]}

# run it
aviso = NotificationManager()
aviso.listen(listeners=listeners)

# wait ...