> On 23 Apr 2023, at 14:56, Cat22 <[email protected]> wrote:
> 
> I have a C program (Linux) that gets the forecast and inserts it index.php, 
> it needs to run right before the rsync report. The trouble is i cant get it 
> patched into rsyncupload.py properly

it sounds like you tried to modify the rsyncupload.py that ships with weewx, 
but the code you posted later looks nothing like rsyncupload.py

if you decide to modify rsyncupload.py, then you should insert your forecast 
invocation in the 'run' method of the 'RsyncUpload' class.

however, you might want to write a service or generator, that way your changes 
would not have to be re-applied whenever you update weewx.

in the service approach, your code would be executed based on where you specify 
it in the 'Services' section of the 'Engine' stanza in your weewx config.  that 
is kind of tricky - it is not clear to me whether you generator your index.php 
using weewx, or with the c program, or something else.  and without that 
information, i cannot tell you when to invoke the service.

in the generator approach, your code would be executed based on where you 
specify it in the 'Generators' section of the skin config (or, by 
inheritance/overrides, the skin config in your weewx config). 

the service code would look something like this (in the file user/fc.py):

```
import os
import weewx
from weewx.engine import StdService

class ForecastGrabberService(StdService):
    def new_archive_record(self, event):
        os.system("/usr/local/bin/weewx/skins/ss/forecast")
```

then add it to the service list in your weewx config.

the generator code would look something like this (in the file user/fc.py):

```
import os

class ForecastGrabberGenerator(object):
    def run(self):
        os.system("/usr/local/bin/weewx/skins/ss/forecast")
```

then add it to the generator list in your skin config:

```
[Generators]
    generator_list = weewx.cheetahgenerator.CheetahGenerator, ..., 
weewx.reportengine.CopyGenerator, user.fc.ForecastGrabberGenerator
```

that way the pages would be generated and copied to the local report area as 
usual, then your forecast-thingy would do its thing.  then after that the rsync 
would happen, based on whatever you defined in the StdReport section of your 
weewx config.

please see the customization guide for examples of how to specify parameters 
and do proper logging.

finally, you need to test your code to ensure that you handle the callout to 
the c program properly.  do that by defining a 'main' within your code so that 
you can invoke it independently of the weewx engine - you want to run with 
weewx plumbing, but not with the weewx engine controlling everything.

these assume that you use 'system' to invoke the c code.  subprocess would give 
you better control and access to stdout/stderr.

you want it to block until the c code finishes, but you might want to build in 
a timeout in case the c code hangs.  and you almost certainly want to capture 
the stdout/stderr from the c code, and handle any return status properly so 
that you can log it in weewx.  that is an exercise left for a longer email.

m

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/D253FC50-FC71-4F47-9F52-5B8891E6D7AE%40gmail.com.

Reply via email to