Problem writing a search list extension

47 views
Skip to first unread message

Mike Hawkins

unread,
Jul 26, 2020, 5:00:53 AM7/26/20
to weewx-development
Hi,
I'm hoping somebody can point out what I'm doing wrong here, it's probably trivial but I'm tearing my hair out and have no idea where things are going wrong.

I have several stations and therefore several databases, so I wanted a version of the $alltime tag provided by the example stats.py or xstats.py that would take a data_binding.  With some searching I came up with this


"""
"""

import weewx.units
from weewx.cheetahgenerator import SearchList
from weewx.tags import TimespanBinder, TimeBinder
from weeutil.weeutil import TimeSpan


class MyStats(SearchList):

    def __init__(self, generator):
        SearchList.__init__(self, generator)

    def get_extension_list(self, timespan, db_lookup):

        class DBBinder(TimeBinder):

            # "alltime", with optional parameter data_binding
            def alltime(self, data_binding=None):
                return TimespanBinder(timespan,
                                      self.db_lookup,
                                      context='year',
                                      data_binding=data_binding,
                                      formatter=self.formatter,
                                      converter=self.converter)

        binder = DBBinder(db_lookup,
                          timespan,
                          self.generator.formatter,
                          self.generator.converter)
        return [binder]

which works perfectly if the report is generated via wee_reports.
However it fails in the normal report run with:

Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine: Caught unrecoverable exception in generator 'weewx.cheetahgenerator.CheetahGenerator'
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****  name 'weewx' is not defined
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****  Traceback (most recent call last):
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/reportengine.py", line 197, in run
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      obj.start()
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/reportengine.py", line 280, in start
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      self.run()
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/cheetahgenerator.py", line 150, in run
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      ngen = self.generate(gen_dict[section_name], self.gen_ts)
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/cheetahgenerator.py", line 220, in generate
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      ngen += self.generate(section[subsection], gen_ts)
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/cheetahgenerator.py", line 220, in generate
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      ngen += self.generate(section[subsection], gen_ts)
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/cheetahgenerator.py", line 308, in generate
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      searchList = self._getSearchList(encoding, timespan,
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/weewx/cheetahgenerator.py", line 376, in _getSearchList
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****      searchList += obj.get_extension_list(timespan, db_lookup)
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****    File "/weewx/package/weewx-4.1.0/bin/user/mstats.py", line 18, in get_extension_list
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****  NameError: name 'weewx' is not defined
Jul 26 09:50:17 bee weewx-weewx[192470] ERROR weewx.reportengine:         ****  Generator terminated
Jul 26 09:50:17 bee weewx-weewx[192470] INFO weewx.reportengine: Copied 0 files to /weewx/www/live


Other than this problem my weewx config is quite happy and the other extensions are working fine so I don't think there is anything fundamentally wrong with my setup even though it is in a non-standard location.

Any pointers very gratefully received.

Best

Mike


mstats.py
log.txt

Mike Hawkins

unread,
Jul 26, 2020, 11:51:31 AM7/26/20
to weewx-development
Drat,
I knew it was going to be trivial.  Turn it off and on again and everything works now.

Sorry

Mike

Tom Keffer

unread,
Jul 26, 2020, 11:52:23 AM7/26/20
to Mike Hawkins, weewx-development
I tried your file mstats.py on my machine, and it worked fine. Perhaps it is a PYTHONPATH problem?

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/baafe0ef-59d5-4de4-80e5-7abc8958d0ebn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages