You are missing a search list extension called "stats". I suspect that this
is the old stats module that came with WeeWX until v4.6.

If that's the case, I've attached it. Put it in /etc/weewx/bin/user

If it came from somewhere else, I have no idea what it is. Or, perhaps you
don't use it at all.

On Wed, Mar 6, 2024 at 12:32 PM salinois <salin...@gmail.com> wrote:

> OK, I took that, thanks.
>
> but I use this command:
>
> # Reconfigure to use your hardware*weectl station reconfigure
>
> *watch:
>
> [weectl station reconfigure
> Using configuration file /etc/weewx/weewx.conf
> Processing configuration file /etc/weewx/weewx.conf
>
> Give a description of the station. This will be used for the title of reports.
> description [Loulle, Jura (France)]:
>
> Specify altitude, with units 'foot' or 'meter'.  For example:
>   35, foot
>   12, meter
> altitude [700, meter]:
>
> Specify latitude in decimal degrees, negative for south.
> latitude [46.2539]:
> Specify longitude in decimal degrees, negative for west.
> longitude [5.3168]:
>
> Choose a unit system for the reports. Later, you can modify
> your choice, or choose a combination of units. Unit systems
> include:
>   us         (ºF, inHg, in, mph)
>   metricwx   (ºC, mbar, mm, m/s)
>   metric     (ºC, mbar, cm, km/h)
> unit system [us]:
>
> Choose a driver. Installed drivers include:
>   0) BYOWS           (user.byows)
>   1) AcuRite         (weewx.drivers.acurite)
>   2) BYOWS           (weewx.drivers.byows)
>   3) CC3000          (weewx.drivers.cc3000)
>   4) FineOffsetUSB   (weewx.drivers.fousb)
>   5) Simulator       (weewx.drivers.simulator)
>   6) TE923           (weewx.drivers.te923)
>   7) Ultimeter       (weewx.drivers.ultimeter)
>   8) Vantage         (weewx.drivers.vantage)
>   9) WMR100          (weewx.drivers.wmr100)
>  10) WMR300          (weewx.drivers.wmr300)
>  11) WMR9x8          (weewx.drivers.wmr9x8)
>  12) WS1             (weewx.drivers.ws1)
>  13) WS23xx          (weewx.drivers.ws23xx)
>  14) WS28xx          (weewx.drivers.ws28xx)
> driver: 0
>
> You can register the station on weewx.com, where it will be included in a
> map. If you choose to register, you will also need a unique URL to identify
> the station (such as a website, or a WeatherUnderground link).
> register this station (y/n)? [n]
> Saving configuration file /etc/weewx/weewx.conf
> Saved old configuration file as /etc/weewx/weewx.conf.20240306210700]
>
> And this is better.
>
> sudo systemctl restart weewx.service
> pi@raspberrypi:~/Documents $ sudo systemctl status weewx.service
> ● weewx.service - WeeWX
>      Loaded: loaded (/lib/systemd/system/weewx.service; enabled; vendor 
> preset: enabled)
>      Active: active (running) since Wed 2024-03-06 21:07:54 CET; 2s ago
>        Docs: https://weewx.com/docs
>    Main PID: 30869 (python3)
>       Tasks: 4 (limit: 4915)
>         CPU: 577ms
>      CGroup: /system.slice/weewx.service
>              └─30869 python3 /usr/share/weewx/weewxd.py /etc/weewx/weewx.conf
>
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.restx: CWOP: Posting 
> not enabled.
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.restx: WOW: Posting 
> not enabled.
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.restx: AWEKAS: Posting 
> not enabled.
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.engine: 'pyephem' 
> detected, extended almanac data is available
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO __main__: Starting up weewx 
> version 5.0.2
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.engine: Using binding 
> 'wx_binding' to database 'weewx.sdb'
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.manager: Starting 
> backfill of daily summaries
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.manager: Daily 
> summaries up to date
> mars 06 21:07:54 raspberrypi weewxd[30869]: INFO weewx.engine: Starting main 
> packet loop.
> mars 06 21:07:54 raspberrypi weewxd.py[30869]: BYOWS RPi: Unknown Wind Vane 
> value: 0.0
> but I have again these ERRORS !!!
>
> [Mar  6 21:30:16 raspberrypi weewxd[31170]: INFO weewx.manager: Added record 
> 2024-03-06 21:30:00 CET (1709757000) to database 'weewx.sdb'
> Mar  6 21:30:16 raspberrypi weewxd[31170]: INFO weewx.manager: Added record 
> 2024-03-06 21:30:00 CET (1709757000) to daily summary in 'weewx.sdb'
> Mar  6 21:30:16 raspberrypi weewxd.py: BYOWS RPi: Unknown Wind Vane value: 0.0
> Mar  6 21:30:17 raspberrypi weewxd[31170]: INFO weewx.cheetahgenerator: 
> Generated 8 files for report SeasonsReport in 1.26 seconds
> Mar  6 21:30:18 raspberrypi weewxd[31170]: INFO weewx.imagegenerator: 
> Generated 15 images for report SeasonsReport in 0.69 seconds
> Mar  6 21:30:18 raspberrypi weewxd[31170]: INFO weewx.reportengine: Copied 0 
> files to /var/www/html/weewx
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine: Caught 
> unrecoverable exception in generator 'weewx.cheetahgenerator.CheetahGenerator'
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****  No module named 'user.stats'
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****  Traceback (most recent call last):
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "/usr/share/weewx/weewx/reportengine.py", line 220, in run
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****      obj.start()
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "/usr/share/weewx/weewx/reportengine.py", line 409, in start
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****      self.run()
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 163, in run
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****      self.init_extensions(gen_dict[section_name])
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 194, in 
> init_extensions
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****      klass = weeutil.weeutil.get_object(x)
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "/usr/share/weewx/weeutil/weeutil.py", line 1404, in get_object
> Mar  6 21:30:18 raspberrypi weewxd[31170]: Traceback (most recent call last):
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File 
> "/usr/share/weewx/weewx/reportengine.py", line 220, in run
> Mar  6 21:30:18 raspberrypi weewxd[31170]:     obj.start()
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File 
> "/usr/share/weewx/weewx/reportengine.py", line 409, in start
> Mar  6 21:30:18 raspberrypi weewxd[31170]:     self.run()
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File 
> "/usr/share/weewx/weewx/cheetahgenerator.py", line 163, in run
> Mar  6 21:30:18 raspberrypi weewxd[31170]:     
> self.init_extensions(gen_dict[section_name])
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File 
> "/usr/share/weewx/weewx/cheetahgenerator.py", line 194, in init_extensions
> Mar  6 21:30:18 raspberrypi weewxd[31170]:     klass = 
> weeutil.weeutil.get_object(x)
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File 
> "/usr/share/weewx/weeutil/weeutil.py", line 1404, in get_object
> Mar  6 21:30:18 raspberrypi weewxd[31170]:     module = 
> importlib.import_module(module_name)
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File 
> "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
> Mar  6 21:30:18 raspberrypi weewxd[31170]:     return 
> _bootstrap._gcd_import(name[level:], package, level)
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File "<frozen 
> importlib._bootstrap>", line 1030, in _gcd_import
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File "<frozen 
> importlib._bootstrap>", line 1007, in _find_and_load
> Mar  6 21:30:18 raspberrypi weewxd[31170]:   File "<frozen 
> importlib._bootstrap>", line 984, in _find_and_load_unlocked
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ModuleNotFoundError: No module 
> named 'user.stats'
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****      module = importlib.import_module(module_name)
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "/usr/lib/python3.9/importlib/__init__.py", line 127, in 
> import_module
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****      return _bootstrap._gcd_import(name[level:], package, level)
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****    File "<frozen importlib._bootstrap>", line 984, in 
> _find_and_load_unlocked
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****  ModuleNotFoundError: No module named 'user.stats'
> Mar  6 21:30:18 raspberrypi weewxd[31170]: ERROR weewx.reportengine:         
> ****  Generator terminated
> Mar  6 21:30:18 raspberrypi weewxd.py: BYOWS RPi: Unknown Wind Vane value: 
> 0.0]
>
> but, I don't again modify all the weewx.conf, maybe normaly......
>
> Patrick
>
>
>
> Le 06/03/2024 à 21:13, Tom Keffer a écrit :
>
> It should be
>
> driver = user.byows
>
> On Wed, Mar 6, 2024 at 11:29 AM salinois <salin...@gmail.com> wrote:
>
>> ok Tom,
>>
>> this is a fresh install, not upgrade, but When I put my other sd card
>> with 4.9 version, it is ok, so, it is not a issue with GPIO, I think.
>>
>> And yes, the driver is here:
>>
>> [ls -ail /etc/weewx/bin/user/
>> total 32
>> 526359 drwxrwsr-x 3 weewx weewx  4096  6 mars  18:32 .
>> 526358 drwxrwsr-x 3 weewx weewx  4096  7 févr. 22:15 ..
>> 524298 -rw-r--r-- 1 weewx weewx 10990  8 févr. 13:05 byows.py
>> 526361 -rw-rw-r-- 1 weewx weewx   541  7 févr. 22:15 extensions.py
>> 526360 -rw-rw-r-- 1 weewx weewx   306  7 févr. 22:15 __init__.py
>> 655698 drwxr-sr-x 2 weewx weewx  4096  6 mars  18:32 __pycache__]
>>
>>
>> and the lines for the driver in weewx.conf are:
>>
>>
>> *[Station]*
>>
>>     # Description of the station location, such as your town.
>>     location = "Loulle, Jura (France)"
>>
>>     # Latitude in decimal degrees. Negative for southern hemisphere.
>>     latitude = 46.2539
>>     # Longitude in decimal degrees. Negative for western hemisphere.
>>     longitude = 5.3168
>>
>>     # Altitude of the station, with the unit it is in. This is used only
>>     # if the hardware cannot supply a value.
>>     altitude = 700, meter    # Choose 'foot' or 'meter' for unit
>>
>>     # Set to type of station hardware. There must be a corresponding
>> stanza
>>     # in this file, which includes a value for the 'driver' option.
>>    * station_type = BYOWS*
>>
>> and next
>>
>>
>>
>>
>>
>> *#################################################################################
>> [BYOWS]    * # This section is for the Raspberry Pi Bring Your Own
>> Weather Station driver.
>>
>>     # The driver to use
>> *     driver = byows ===> is it the good syntax ? *in version 4.9 I have
>> user.byows
>>
>> but now, there no more errors:
>>
>> [ sudo systemctl status weewx.service
>> ● weewx.service - WeeWX
>>      Loaded: loaded (/lib/systemd/system/weewx.service; enabled; vendor
>> preset: enabled)
>>      Active: failed (Result: exit-code) since Wed 2024-03-06 20:21:34
>> CET; 3s ago
>>        Docs: https://weewx.com/docs
>>     Process: 29896 ExecStart=weewxd /etc/weewx/weewx.conf (code=exited,
>> status=1/FAILURE)
>>    Main PID: 29896 (code=exited, status=1/FAILURE)
>>         CPU: 337ms
>>
>> mars 06 20:21:34 raspberrypi weewxd[29896]:
>> self.setupStation(config_dict)
>> mars 06 20:21:34 raspberrypi weewxd[29896]:   File
>> "/usr/share/weewx/weewx/engine.py", line 104, in setupStation
>> mars 06 20:21:34 raspberrypi weewxd[29896]:     __import__(driver)
>> mars 06 20:21:34 raspberrypi weewxd[29896]: ModuleNotFoundError: *No
>> module named 'byows'*
>> mars 06 20:21:34 raspberrypi weewxd[29896]: CRITICAL __main__:
>> ****    File "/usr/share/weewx/weewx/engine.py", line 104, in setupStation
>> mars 06 20:21:34 raspberrypi weewxd[29896]: CRITICAL __main__:
>> ****      __import__(driver)
>> mars 06 20:21:34 raspberrypi weewxd[29896]: CRITICAL __main__:     ****
>> ModuleNotFoundError: No module named 'byows'
>> mars 06 20:21:34 raspberrypi weewxd[29896]: CRITICAL __main__:     ****
>> Exiting.
>> mars 06 20:21:34 raspberrypi systemd[1]: weewx.service: Main process
>> exited, code=exited, status=1/FAILURE
>> mars 06 20:21:34 raspberrypi systemd[1]: weewx.service: Failed with
>> result 'exit-code'.]
>>
>> Patrick
>>
>>
>>
>>
>> Le 06/03/2024 à 19:23, Tom Keffer a écrit :
>>
>> If you did a package install, the driver byows.py should go in
>> /etc/weewx/bin/user. But, frankly, this should have been done for you if
>> you did an upgrade from V4 to V5. Take a look in /etc/weewx/bin/user and
>> see if it's in there.
>>
>> But, the error in the little snippet from your status report is a
>> different one. For some reason, your installation thinks it is not running
>> on a Raspberry Pi, so it cannot access the gpio pins. I'm not an expert on
>> that, but it may be due to a missing installation package.
>>
>> On Wed, Mar 6, 2024 at 10:13 AM salinois <salin...@gmail.com> wrote:
>>
>>> again me
>>>
>>> perhaps , I found
>>>
>>> Should I use this method now?
>>>
>>> [weectl extension install /home/pi/byows.py]
>>>
>>> and after:
>>>
>>> weectl station reconfigures --no-prompt --driver=weewx.drivers.byows
>>>
>>>
>>> Patrick
>>> Le 06/03/2024 à 18:47, salinois a écrit :
>>>
>>> hello,
>>>
>>> I restart my installation with version weewx 5.0.1 and I have these
>>> errors:
>>>
>>> on my version which works in 4.10.2, my "byows.py" driver is located
>>> here: [/usr/share/weewx/user/] but I saw that the tree structure has
>>> changed; where should I put my driver now?
>>>
>>> watch these errors:
>>>
>>> sudo systemctl status weewx.service
>>> ● weewx.service - WeeWX
>>>      Loaded: loaded (/lib/systemd/system/weewx.service; enabled; vendor
>>> preset: enabled)
>>>      Active: failed (Result: exit-code) since Wed 2024-03-06 18:32:05
>>> CET; 2s ago
>>>        Docs: https://weewx.com/docs
>>>     Process: 11182 ExecStart=weewxd /etc/weewx/weewx.conf (code=exited,
>>> status=4)
>>>    Main PID: 11182 (code=exited, status=4)
>>>         CPU: 682ms
>>>
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL weewx.engine:
>>> ****      pin = self.pin_factory.pin(pin)
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL weewx.engine:
>>> ****    File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line
>>> 103, in pin
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL weewx.engine:
>>> ****      pin = self.pin_class(self, n)
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL weewx.engine:
>>> ****    File "/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py",
>>> line 111, in __init__
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL weewx.engine:
>>> ****      GPIO.setup(self.number, GPIO.IN,
>>> self.GPIO_PULL_UPS[self._pull])
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL weewx.engine:
>>> ****  RuntimeError: Not running on a RPi!
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL __main__:* Unable
>>> to load driver: Not running on a RPi!*
>>> mars 06 18:32:05 raspberrypi weewxd[11182]: CRITICAL __main__:     ****
>>> Exiting...
>>> mars 06 18:32:05 raspberrypi systemd[1]: weewx.service: Main process
>>> exited, code=exited, status=4/NOPERMISSION
>>> mars 06 18:32:05 raspberrypi systemd[1]: weewx.service: Failed with
>>> result 'exit-code'.
>>>
>>> Patrick
>>> Le 08/02/2024 à 08:59, salinois a écrit :
>>>
>>> hello Matthew
>>>
>>> OK I understand if that works
>>>
>>> thanks also to vince.
>>>
>>> Now , I must to try the 5.0.0 version
>>>
>>> Patrick
>>> Le 07/02/2024 à 23:06, matthew wall a écrit :
>>>
>>> On Wednesday, February 7, 2024 at 3:36:55 PM UTC-5 sali...@gmail.com
>>> wrote:
>>>
>>> pi@raspberrypi:~ $ wget -qO - https://weewx.com/apt/weewx-python3.list
>>> | sudo tee /etc/apt/sources.list.d/weewx.list
>>> *deb [arch=all] http://weewx.com/apt/python3
>>> <http://weewx.com/apt/python3> buster main ==> why Buster*
>>>
>>>
>>> 'buster' (i.e., debian 10) is the oldest release on which the deb
>>> package will install.
>>>
>>> if you look at the python2 configuration, it uses the label 'squeeze'
>>> (debian 6)
>>>
>>> the weewx packages are *really* stable with respect to dependencies, so
>>> the same package that works with debian 10 also works with debian 11 and
>>> debian 12.  besides, i am too old and lazy to build a new deb and new apt
>>> repository for every major debian release that comes out :)
>>>
>>> --
>>> 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 weewx-user+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/weewx-user/ca7d09e7-acd7-4115-ae62-7ac60a1ef82bn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/weewx-user/ca7d09e7-acd7-4115-ae62-7ac60a1ef82bn%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 weewx-user+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/weewx-user/320351a0-1a0a-4474-9c39-de81a0e01011%40gmail.com
>>> <https://groups.google.com/d/msgid/weewx-user/320351a0-1a0a-4474-9c39-de81a0e01011%40gmail.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 weewx-user+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/weewx-user/CAPq0zEA%3DtRcHr84k%2BigR-nQtPbaxsZTHoV7u2rnED7wr2QYQWg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/weewx-user/CAPq0zEA%3DtRcHr84k%2BigR-nQtPbaxsZTHoV7u2rnED7wr2QYQWg%40mail.gmail.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 weewx-user+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/weewx-user/e38a1a56-974c-4fa8-804c-b095698ed7df%40gmail.com
>> <https://groups.google.com/d/msgid/weewx-user/e38a1a56-974c-4fa8-804c-b095698ed7df%40gmail.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 weewx-user+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/CAPq0zECppBi9R8cp2ZvBtagbfuWQDUdmz58Ry-KLDya%2BW11dDA%40mail.gmail.com
> <https://groups.google.com/d/msgid/weewx-user/CAPq0zECppBi9R8cp2ZvBtagbfuWQDUdmz58Ry-KLDya%2BW11dDA%40mail.gmail.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 weewx-user+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/ec687b6e-de74-4e9d-9870-53fbdbc8385b%40gmail.com
> <https://groups.google.com/d/msgid/weewx-user/ec687b6e-de74-4e9d-9870-53fbdbc8385b%40gmail.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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAPq0zEDSxwrcxbgKMhRrk919eiZWYNw_UT8PG%2BbcAEcVLJZcUw%40mail.gmail.com.
#    Copyright (c) 2009-2015 Tom Keffer <tkef...@gmail.com>
#    See the file LICENSE.txt for your rights.

"""Example of how to extend the search list used by the Cheetah generator.

*******************************************************************************

This search list extension offers two extra tags:

    'alltime':   All time statistics.
                 For example, "what is the all time high temperature?"

    'seven_day': Statistics for the last seven days.
                 That is, since midnight seven days ago.

*******************************************************************************

To use this search list extension:

1) Copy this file to the user directory. See https://bit.ly/33YHsqX for where your user
directory is located.

2) Modify the option search_list in the skin.conf configuration file, adding
the name of this extension.  When you're done, it will look something like
this:

[CheetahGenerator]
    search_list_extensions = user.stats.MyStats

You can then use tags such as $alltime.outTemp.max for the all-time max
temperature, or $seven_day.rain.sum for the total rainfall in the last
seven days.

*******************************************************************************
"""
import datetime
import time

from weewx.cheetahgenerator import SearchList
from weewx.tags import TimespanBinder
from weeutil.weeutil import TimeSpan

class MyStats(SearchList):                                                   # 1

    def __init__(self, generator):                                           # 2
        SearchList.__init__(self, generator)
    
    def get_extension_list(self, timespan, db_lookup):                       # 3
        """Returns a search list extension with two additions.
        
        Parameters:
          timespan: An instance of weeutil.weeutil.TimeSpan. This will
                    hold the start and stop times of the domain of 
                    valid times.

          db_lookup: This is a function that, given a data binding
                     as its only parameter, will return a database manager
                     object.
        """

        # First, create TimespanBinder object for all time. This one is easy
        # because the object timespan already holds all valid times to be
        # used in the report.
        all_stats = TimespanBinder(timespan, 
                                   db_lookup,
                                   context='year',
                                   formatter=self.generator.formatter,
                                   converter=self.generator.converter,
                                   skin_dict=self.generator.skin_dict)       # 4
        
        # Now get a TimespanBinder object for the last seven days. This one we
        # will have to calculate. First, calculate the time at midnight, seven
        # days ago. The variable week_dt will be an instance of datetime.date.
        week_dt = datetime.date.fromtimestamp(timespan.stop) \
                  - datetime.timedelta(weeks=1)                              # 5
        # Convert it to unix epoch time:
        week_ts = time.mktime(week_dt.timetuple())                           # 6
        # Form a TimespanBinder object, using the time span we just
        # calculated:
        seven_day_stats = TimespanBinder(TimeSpan(week_ts, timespan.stop),
                                         db_lookup,
                                         context='week',
                                         formatter=self.generator.formatter,
                                         converter=self.generator.converter,
                                         skin_dict=self.generator.skin_dict) # 7

        # Now create a small dictionary with keys 'alltime' and 'seven_day':
        search_list_extension = {'alltime'   : all_stats,
                                 'seven_day' : seven_day_stats}              # 8
        
        # Finally, return our extension as a list:
        return [search_list_extension]                                       # 9

Reply via email to