I had completely forgotten about the .spans() iterator! Well done!
On Sun, Feb 2, 2020 at 11:36 AM Hyrules Hyrules <hyru...@gmail.com> wrote: > Actually it's quite easy for those who would like to do it here is the > code for the search list extension. All I need is to remove the first spans > in the list and voila. This gives me all spans in intervals of 15 minutes > from 2 days ago to closes quarter to now. > > # BASED ON BELCHERTOWN PYTHON FILE START > > from __future__ import with_statement > import datetime > import time > import calendar > import json > import os > import os.path > import syslog > import sys > import locale > > import weewx > import weecfg > import configobj > import weedb > import weeutil.weeutil > import weewx.reportengine > import weewx.station > import weewx.units > import weewx.tags > import weewx.uwxutils > > from collections import OrderedDict > > from weewx.cheetahgenerator import SearchList > from weewx.tags import TimespanBinder > from weeutil.weeutil import to_bool, TimeSpan, to_int, archiveDaySpan, > archiveWeekSpan, archiveMonthSpan, archiveYearSpan, startOfDay, > timestamp_to_string, option_as_list > try: > from weeutil.config import search_up > except: > # Pass here because chances are we have an old version of weewx which > will get caught below. > pass > > # Check weewx version. Many things like search_up, weeutil.weeutil.KeyDict > (label_dict) are from 3.9 > if weewx.__version__ < "3.9": > raise weewx.UnsupportedFeature("weewx 3.9 and newer is required, found > %s" % weewx.__version__) > > reload(sys) > sys.setdefaultencoding("utf-8") > > def logmsg(level, msg): > syslog.syslog(level, 'Hydrometeo Extension: %s' % msg) > > def logdbg(msg): > logmsg(syslog.LOG_DEBUG, msg) > > def loginf(msg): > logmsg(syslog.LOG_INFO, msg) > > def logerr(msg): > logmsg(syslog.LOG_ERR, msg) > > # Print version in syslog for easier troubleshooting > VERSION = "0.1" > loginf("version %s" % VERSION) > > class HydroMeteoStats(SearchList): > def __init__(self, generator): > SearchList.__init__(self, generator) > > def get_extension_list(self, timespan, db_lookup): > today = datetime.datetime.now() > twodaysago = datetime.datetime.now() - datetime.timedelta(days=2) > > twodaysago = twodaysago.replace(hour=00, minute=00, second=00, > microsecond=00) #.strftime("%Y-%m-%d %H:%M:%S") > > tsb = TimespanBinder(TimeSpan(time.mktime(twodaysago.timetuple()), > time.mktime(today.timetuple())), db_lookup,formatter=self.generator.formatter, > converter=self.generator.converter) > spans = tsb.spans(interval=900) > last2days = spans > > search_list_extension = {'last2days' : last2days} > > return [search_list_extension] > > > > On Saturday, February 1, 2020 at 12:42:45 PM UTC-5, Hyrules Hyrules wrote: >> >> Hi everyone, >> >> I was wondering if there is an actual way of doing this in the cheetah >> templating engine. >> >> I would like to get the following information in my file : >> >> - last 2 days of archive >> - starting at midnight and 15 minutes >> - in intervals of 15 minutes >> - all through today closest to the quarter of the hour (eg if it's 12:47 >> -> 12:45, 1:24 -> 1:15) >> >> I'm not sure if it's possible using the pre-existing $span or $day >> variables. I`ve been trying some stuff apparently unsucessfully. >> >> Any input would be appreciated. >> >> Thanks. >> > -- > 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/7b7cbbca-2d25-493f-a77c-2169be26b6f4%40googlegroups.com > <https://groups.google.com/d/msgid/weewx-user/7b7cbbca-2d25-493f-a77c-2169be26b6f4%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/CAPq0zEAJ9fE9rYCW7hWno7O6rjMaB4F_mBCY88a5Yy7vPPq%2BLQ%40mail.gmail.com.