Re: [weewx-development] Problem writing a search list extension
I tried your file mstats.py on my machine, and it worked fine. Perhaps it is a PYTHONPATH problem? On Sun, Jul 26, 2020 at 2:00 AM Mike Hawkins wrote: > 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 > > https://duckrising.com/weewx/ > > -- > You received this message
[weewx-development] Re: Problem writing a search list extension
Drat, I knew it was going to be trivial. Turn it off and on again and everything works now. Sorry Mike https://duckrising.com/weewx/ -- 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-development+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/73f3340d-67b3-41ad-9d23-02b24ac59c8cn%40googlegroups.com.
[weewx-development] Problem writing a search list extension
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 https://duckrising.com/weewx/ -- 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