You want something like:
with open('/path/to/file') as f:
value = f.readline().strip()
event.record['leafTemp1'] = float(value) if value != '' else None
Or, use filepile <https://github.com/tkeffer/filepile>, although that would
require you to change the format of your data file.
-tk
On Mon, Apr 13, 2020 at 4:35 AM Messy Potamia <[email protected]>
wrote:
> I want to read in a single %2.2f from a file "special.dat" and store it
> in something I'll never otherwise use, "leafTemp1".
>
> My weewx is 3.6.2. I have read the suggestion to use a 2nd database,
> however I do not want to do that. I have written a custom .py before to
> read data from a 2-element data file, but I extended the schema to do that
> (and I remember Tom asking why, and it was because I thought that was the
> thing to do, anyway I don't want to do that this time)
>
> pi@RPI3:~ $ cat /home/weewx/special.dat
> 32.67
> pi@RPI3:~ $
>
> Here is the python I copied & modified a few years ago, which works for
> that system:
> #!/usr/bin/env python
>
> #file user/lakedata.py
> import weewx
> from weewx.engine import StdService
>
> class AddLakedata(StdService):
>
> def __init__(self, engine, config_dict):
> # Initialize my superclass first:
> super(AddLakedata, self).__init__(engine, config_dict)
> # Bind to any new archive record events:
> self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_packet)
>
> def new_archive_packet(self, event):
>
> #(code that reads two measurements from a file)
> with open("/mnt/wxdata/weewxmbdata.dat") as f:
> for line in f:
> numbers_str = line.split()
> numbers_float = [float(x) for x in numbers_str]
> value1 = numbers_float[0]
> value2 = numbers_float[1]
>
> event.record['lakeElevation'] = value1
> event.record['lakeWaveheight'] = value2
>
> import schemas.wview
> schema_with_lakedata = schemas.wview.schema + [('lakeElevation', 'REAL')]
> + [('lakeWaveheight', 'REAL')] + [('lightning', 'REAL')]
>
> #
>
> The above code works fine on a previous installation and I'm not going to
> mess with it. This install however, I will be reading a single value, and
> applying it into an existing field in the default existing database. My
> concern is, in the above lakedata.py, which represents an extended schema,
> what changes when I'm using the existing schema?
>
> Thanks for clarifying this for me.
>
> Phil
>
> --
> 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/a7495c2d-f450-46cf-a88f-c75e696f1940%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-user/a7495c2d-f450-46cf-a88f-c75e696f1940%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CAPq0zEAszDV87q37CTGrcTF%3DScm0YQube%2BdqkdY86wLFH_6dqw%40mail.gmail.com.