post-generate.sh -> shellreport.py ?

57 views
Skip to first unread message

Timothy Witham

unread,
Jun 8, 2020, 6:04:16 PM6/8/20
to weewx-user
Hello,

Just replaced my wview with weewx yesterday and like the results so far, thanks!

But now I need to run a command after the archive is updated.  In wview this was easy: just stick any command lines in post-generate.sh and they were executed.  I fail to find an equivalent feature to "shell out" of the python and run external commands from weewx.  It appears I would need to invent a new shellreport.py which would run the commands configured in the config file.  Is this the correct approach?  Or is there an easier way I am missing?

(the reason is I need to run some perl code to update the RRD copy of my data)

mwall

unread,
Jun 8, 2020, 6:45:56 PM6/8/20
to weewx-user


On Monday, June 8, 2020 at 6:04:16 PM UTC-4, Timothy Witham wrote:
Hello,

Just replaced my wview with weewx yesterday and like the results so far, thanks!

But now I need to run a command after the archive is updated.  In wview this was easy: just stick any command lines in post-generate.sh and they were executed.  I fail to find an equivalent feature to "shell out" of the python and run external commands from weewx.  It appears I would need to invent a new shellreport.py which would run the commands configured in the config file.  Is this the correct approach?  Or is there an easier way I am missing?

one approach is to create a service and bind it to archive events.  each time an archive happens, your service is invoke.  then all you have to do in the service is call out to your perl script.  it would look something like this:

from weewx.engine import StdService

class UpdateRRD(StdService):

    def __init__(self, engine, config_dict):
        super(UpdateRRD, self).__init__(engine, config_dict)
        self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)

    def new_archive_record(self, event):
        subprocess.call(["fancy-perl-program.pl"])

not sure how you get data to your perl script, but all of the fields are available in event.record

see "Customizing the weewx service engine" in the customization guide for more examples:


another approach would be to use python bindings to rrd to do the updates directly.  i used to do that before i found influx and grafana...

Timothy Witham

unread,
Jun 9, 2020, 12:27:25 AM6/9/20
to weewx-user
Thanks for the quick response!  I think this confirms that a simple "shell out" feature doesn't yet exist.  I couldn't find it in extensions either.

My case doesn't need any data from the parent.  It simply selects the records since last update so it can be ran anytime to convert all missing data.  On first run this converts all history which can take a few minutes for years of data.  I could run independent updates after that via cron(1), but ideal timing is to hook it to weewx flow to be available ASAP.

I was thinking of extending the StdReport since this is sort-of an alternative reporting format.  And it will run an external command similar to how RSYNC report does.  But I see value in your approach for a more general purpose shell out.  That event data could be made available to the subprocess via the environment for example.

I'll try to get something working and then adjust my wview-rrd code on github.  Thanks!

-Tim

Timothy Witham

unread,
Jun 9, 2020, 6:06:13 PM6/9/20
to weewx-user
Your approach worked great!  I updated my code to officially support weewx:


Here is the resulting interactive front-end that displays the RRD files:


Thank you sir!

Reply all
Reply to author
Forward
0 new messages