SNEWS2 / SNEWS_Publishing_Tools

Publishing Tool for SNEWS
BSD 3-Clause "New" or "Revised" License
2 stars 2 forks source link

yield message #32

Closed KaraMelih closed 1 month ago

KaraMelih commented 2 years ago

Here https://github.com/SNEWS2/SNEWS_Publishing_Tools/blob/181ed533dbc5768b203f88d609c5954e68a6250e/SNEWS_PT/snews_sub.py#L97 we can yield the alert message therefore, it can be picked by other scripts. yield allows for returning a value without terminating the command.

We can read it here https://github.com/SNEWS2/SNEWS_Publishing_Tools/blob/181ed533dbc5768b203f88d609c5954e68a6250e/SNEWS_PT/__main__.py#L70 and allow for passing the output to other scripts. i.e. it would be something like;

@main.command()
@click.option('--plugin','-p', type='str', default="None")
@click.pass_context
def subscribe(ctx, plugin):
    """ Subscribe to Alert topic
    """
    sub = Subscriber(ctx.obj['env'])
    try:
        alert_message = sub.subscribe()
       if plugin != "None":
           os.system(f"python {plugin} {alert_message}")
    except KeyboardInterrupt:
        pass

Therefore, any plugin script can be given and the alert content is redirected

KaraMelih commented 2 years ago

@Storreslara it is actually rather simple, just those few lines above. However, I'm not sure if yielding the message would print the alert message twice.

In snews_sub we save, and then display the message at the terminal. If we also use yield it might display twice. We should test it

KaraMelih commented 2 years ago

In 4d994e71828762ea6a03f19decf36c0035c606cb I added this but cannot test it yet. I had to update the conda... need a few hours

justinvasel commented 1 month ago

This appears to have been addressed through the aforementioned commit. Closing the issue.