Just a heads up to anyone out there that uses since.py (used to shift
the rain window)
and has upgraded to weewx.4.6.0

I went through the process (I needed the new lang option) and for the
life of me couldn't work out why it kept falling over when generating
various skins.

Switching to a plain skin and adding my cruft back in and lo and
behold it falls over when since.py is slotted back into skin.conf

skin.conf
[CheetahGenerator]
    search_list_extensions = user.since.Since

What then happens is that whenever the trend option is called - such
as in Seasons/current.inc : $trend.barometer.formatted - it raises a
KeyError pointing at 'trend' as the culprit.

Attached is the script since.py and a file with the errors generated
by cheetahgenerator, as found in syslog.

It's way beyond my abilities to work out why it happens, but I'd be
curious to know if it's fixable. :-)

I also hope finding it prevents anyone elses hair loss. :-)

-- 

Cheers
 Glenn

rorpi - read only raspberry pi & various weewx addons
https://github.com/glennmckechnie

-- 
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/CAAraAzgTEeXkgVGFpcpnKdkcrnVwMtvyn5kJTGBe_Qin8WTnxA%40mail.gmail.com.
ERROR weewx.cheetahgenerator: Evaluation of template 
/home/weewx460/skins/Standard2/index.html.tmpl failed with exception '<class 
'KeyError'>'
ERROR weewx.cheetahgenerator: **** Ignoring template 
/home/weewx460/skins/Standard2/index.html.tmpl
ERROR weewx.cheetahgenerator: **** Reason: 'trend'
ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
ERROR weewx.cheetahgenerator: ****    File 
"/home/weewx460/bin/weewx/cheetahgenerator.py", line 344, in generate
ERROR weewx.cheetahgenerator: ****      unicode_string = 
compiled_template.respond()
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_index_html_tmpl.py", line 332, in respond
ERROR weewx.cheetahgenerator: ****    File 
"/usr/local/lib/python3.7/dist-packages/Cheetah/Template.py", line 1708, in 
_handleCheetahInclude
ERROR weewx.cheetahgenerator: ****      
self._CHEETAH__cheetahIncludes[_includeID].respond(trans)
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_current_inc.py", line 464, in respond
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_current_inc.py", line 197, in __errorCatcher19
ERROR weewx.cheetahgenerator: ****    File "<string>", line 1, in <module>
ERROR weewx.cheetahgenerator: ****    File "/home/weewx460/bin/weewx/tags.py", 
line 63, in trend
ERROR weewx.cheetahgenerator: ****      time_delta = 
to_int(self.option_dict['trend'].get('time_delta', 10800))
ERROR weewx.cheetahgenerator: ****  KeyError: 'trend'
ERROR weewx.cheetahgenerator: Evaluation of template 
/home/weewx460/skins/Standard2/myshake/index.html.tmpl failed with exception 
'<class 'KeyError'>'
ERROR weewx.cheetahgenerator: **** Ignoring template 
/home/weewx460/skins/Standard2/myshake/index.html.tmpl
ERROR weewx.cheetahgenerator: **** Reason: 'trend'
ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
ERROR weewx.cheetahgenerator: ****    File 
"/home/weewx460/bin/weewx/cheetahgenerator.py", line 344, in generate
ERROR weewx.cheetahgenerator: ****      unicode_string = 
compiled_template.respond()
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_myshake_index_html_tmpl.py", line 128, in 
respond
ERROR weewx.cheetahgenerator: ****    File 
"/usr/local/lib/python3.7/dist-packages/Cheetah/Template.py", line 1708, in 
_handleCheetahInclude
ERROR weewx.cheetahgenerator: ****      
self._CHEETAH__cheetahIncludes[_includeID].respond(trans)
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_current_inc.py", line 464, in respond
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_current_inc.py", line 197, in __errorCatcher19
ERROR weewx.cheetahgenerator: ****    File "<string>", line 1, in <module>
ERROR weewx.cheetahgenerator: ****    File "/home/weewx460/bin/weewx/tags.py", 
line 63, in trend
ERROR weewx.cheetahgenerator: ****      time_delta = 
to_int(self.option_dict['trend'].get('time_delta', 10800))
ERROR weewx.cheetahgenerator: ****  KeyError: 'trend'
ERROR weewx.cheetahgenerator: Evaluation of template 
/home/weewx460/skins/Standard2/DATA/WL_stickertags.txt.tmpl failed with 
exception '<class 'KeyError'>'
ERROR weewx.cheetahgenerator: **** Ignoring template 
/home/weewx460/skins/Standard2/DATA/WL_stickertags.txt.tmpl
ERROR weewx.cheetahgenerator: **** Reason: 'trend'
ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
ERROR weewx.cheetahgenerator: ****    File 
"/home/weewx460/bin/weewx/cheetahgenerator.py", line 344, in generate
ERROR weewx.cheetahgenerator: ****      unicode_string = 
compiled_template.respond()
ERROR weewx.cheetahgenerator: ****    File 
"_home_weewx460_skins_Standard2_DATA_WL_stickertags_txt_tmpl.py", line 251, in 
respond
ERROR weewx.cheetahgenerator: ****    File "/home/weewx460/bin/weewx/tags.py", 
line 63, in trend
ERROR weewx.cheetahgenerator: ****      time_delta = 
to_int(self.option_dict['trend'].get('time_delta', 10800))
ERROR weewx.cheetahgenerator: ****  KeyError: 'trend'

# since.py
#
# A Search List Extension to provide aggregates since a given hour.
#
# Original author unknown - it's history that's known to me is as follows
#
# https://groups.google.com/d/msg/weewx-user/VyVMEfuxClo/-ppd0N4bBgAJ
#
# Yes I think Gary wrote a python script to work out 9 am.
#
# https://github.com/weewx/weewx/files/2082668/since.py.txt
#
# It is called since.py
#
# There is a bit in the index.html.tmpl
#
#                      <tr>
#                        <td>Today's Rain since 9am</td>
#                        <td>$since($hour=9).rain.sum</td>
#                      </tr>
#
# Further to the above instructions, it requires the following to be inserted
# under the [CheetahGenerator] section, as follows...
#
# [CheetahGenerator]
#     search_list_extensions = user.since.Since
#


# python imports
import datetime
import syslog
import time

# weeWX imports
import weeutil.weeutil
import weewx.cheetahgenerator
import weewx.units

def logmsg(level, msg):
    syslog.syslog(level, 'since: %s' % msg)

def logdbg(msg):
    logmsg(syslog.LOG_DEBUG, msg)

def logdbg2(msg):
   if weewx.debug >= 2:
        logmsg(syslog.LOG_DEBUG, msg)

def loginf(msg):
    logmsg(syslog.LOG_INFO, msg)

def logerr(msg):
    logmsg(syslog.LOG_ERR, msg)


class Since(weewx.cheetahgenerator.SearchList):
    """SLE to provide aggregates since a given time of day."""

    def __init__(self, generator):
        # call our parent's initialisation
        super(Since, self).__init__(generator)

    def get_extension_list(self, timespan, db_lookup):
        """Returns a NewBinder object that supports aggregates since a given
           time.

            The NewBinder object implements the tag $since that allows
            inclusion of aggregates since the last occurrence of a give time of
            day, eg total rainfall since 9am, average temperature since midday.
            The signature of the $since tag is:

            $since([$hour=x]).obstype.aggregation[.optional_unit_conversion][.optional_formatting]

            where

            x is an integer from 0 to 23 inclusive representing the hour of the
            day

            obstype is a field in the archive table in use eg outTemp, inHumidiy
            or rain

            aggregation is an aggregate function supported by weewx (refer
            Customization Guide appendices)

            optional_unit_conversion and optional_formatting are optional weeWX
            unit conversion and formatting codes respectively

        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.

        Returns:
            A NewBinder object with a timespan from "hour" o'clock to the
            report time
          """

        t1 = time.time()

        class NewBinder(weewx.tags.TimeBinder):

            def __init__(self, db_lookup, report_time,
                         formatter=weewx.units.Formatter(),
                         converter=weewx.units.Converter(), **option_dict):
                # call our parents initialisation
                super(NewBinder, self).__init__(db_lookup, report_time,
                                                formatter=formatter,
                                                converter=converter,
                                                **option_dict)

            def since(self, data_binding=None, hour=0, minute=0, today=True):
                """Return a TimeSpanBinder for the period since 'hour'."""

                # get datetime obj for the time of our report
                stop_dt = datetime.datetime.fromtimestamp(timespan.stop)
                # the timespan we want may be wholly within today or may have
                # started yesterday, it depends on the value of the hour
                # parameter
                # first, get time obj for "hour" o'clock
                hour_t = datetime.time(hour, minute)
                if stop_dt.hour >= hour and stop_dt.minute >= minute:
                    # our timespan is solely within today, the start ts is at
                    # "hour" o'clock
                    # get datetime obj for "hour" o'clock today
                    hour_dt = datetime.datetime.combine(stop_dt, hour_t)
                else:
                    # our timespan starts yesterday and finishes today, so our
                    # start ts is "hour" o'clock yesterday
                    # first, get a datetime object for yesterday
                    yest_dt = stop_dt + datetime.timedelta(days=-1)
                    # get datetime obj for "hour" o'clock yesterday
                    hour_dt = datetime.datetime.combine(yest_dt, hour_t)
                # now get a ts, that is our start ts
                start_ts = time.mktime(hour_dt.timetuple())
                # and put together our timespan as a TimeSpan object
                tspan = weeutil.weeutil.TimeSpan(start_ts, timespan.stop)

                if today:
                    logdbg2("Since Start {}, Since stop {}".format(start_ts, timespan.stop))
                else:
                    # now subtract 1 day from our new datetime object
                    yest_dt = hour_dt + datetime.timedelta(days=-1)
                    # convert our yesterday datetime object to a timestamp
                    yest_ts = time.mktime(yest_dt.timetuple())

                    # and put together our timespan as a TimeSpan object
                    tspan = weeutil.weeutil.TimeSpan(yest_ts, start_ts)

                    logdbg2("SinceYesterday Start {}, Since stop {}".format(yest_ts, start_ts))

                # now return a TimespanBinder object, using the timespan we
                # just calculated
                return weewx.tags.TimespanBinder(tspan,
                                                 self.db_lookup,
                                                 context='hour',
                                                 data_binding=data_binding,
                                                 formatter=self.formatter,
                                                 converter=self.converter)

        tspan_binder = NewBinder(db_lookup,
                                timespan.stop,
                                self.generator.formatter,
                                self.generator.converter)

        t2 = time.time()
        logdbg2("Since SLE executed in %0.3f seconds" % (t2-t1))

        return [tspan_binder]

Reply via email to