On Monday, February 18, 2019 at 9:40:56 PM UTC-5, rich T wrote:
>
> I'm able to transpose current data onto a captured image using PIL and 
> querying the database. It is still a work in progress.  Was wondering if 
> creating a service would be the best way to go forward? 
>

you could do it as a service.  but it might be better to do it as a weewx 
generator.

create the file 'wxoverlay.py' in your weewx user directory, with contents 
something like this:

import weewx
import weewx.reportengine

class WXOverlayGenerator(weewx.reportengine.ReportGeneraor):
    def run(self):
        filename = self.skin_dict.get('filename', '/var/tmp/image.png')
        # query the database for latest wind speed and direction
        dbmgr = self.db_binder.get_manager()
        ts = dbmgr.lastGoodStamp()
        if ts is None:
            # there may be no archive data yet
            return
        record = dbmgr.getRecord(ts)
        # wind speed and dir may not be in the record (depends on the 
schema) and may be None
        windSpeed = record.get('windSpeed')
        windDir = record.get('windDir')
        # Open the file with the binary image...
        with open(filename, 'rb+') as fd:
            # ... read it ...
            image = fd.read()
            # ... then manipulate it
            new_image = self.fancy_function_to_overlay_wind(image, 
windSpeed, windDir)
            # Replace the old image with the new image
            fd.seek(0)
            fd.write(image)
            fd.truncate()

    def fancy_function_to_overlay_wind(self, image, wind_speed, wind_dir):
        # do your fancy stuff here
        pass


then in your weewx configuration (or skin.conf) tell it to run in the skin:

[WXOverlayGenerator]
    filename = /var/tmp/image.png

[StdReport]
    ...
    [[ReportWithOverlay]]
        skin = Seasons
        ...
        [[[Generators]]]
            generator_list = ..., user.wxoverlay.WXOverlayGenerator


for an example of a working generator, see the weewx-sftp generator, and 
see the section 'The database' in the weewx customization guide for 
examples of how to bind to the database.

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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to