multiple bindings with Seasons hilo.inc?

51 views
Skip to first unread message

Michael

unread,
Sep 5, 2019, 8:32:47 AM9/5/19
to weewx-user
Hello,

Is it possible to use multiple bindings in Seasons hilo.inc?
If so, how do you do it right?

 

      <tr>

        <td class="label">$obs.label.extraTemp6</td>

        #for $archive in $archive_data

        <td class="data new_row hilo_$archive[0]">

          <span title="$archive[1]($data_binding='sdr_binding').extraTemp6.maxtime">

            $archive[1]($data_binding='sdr_binding').extraTemp6.max.format(add_label=False)</span><br/>

          <span title="$archive[1]($data_binding='sdr_binding').extraTemp6.mintime">

            $archive[1]($data_binding='sdr_binding').extraTemp6.min.format(add_label=False)</span>

        </td>

        #end for

        <td class="units">$unit.label.extraTemp6</td>

      </tr>

 

---->

 

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: cheetahgenerator: Generate failed with exception '<type 'exceptions.SyntaxError'>'

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: cheetahgenerator: **** Ignoring template /home/weewx/skins/Seasons-TFA/index.html.tmpl

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: cheetahgenerator: **** Reason: keyword can't be an expression (_home_weewx_skins_Seasons_TFA_hilo_inc.py, line 162)

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****  Traceback (most recent call last):

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****    File "/home/weewx/bin/weewx/cheetahgenerator.py", line 332, in generate

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****      fd.write(str(compiled_template))

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1045, in __str__

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****      rc = getattr(self, mainMethName)()

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****    File "_home_weewx_skins_Seasons_TFA_index_html_tmpl.py", line 352, in respond

Sep 1 14:15:29 raspberrypi weewx-tfa[6844]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1685, in _handleCheetahInclude

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****      file=file)

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 832, in compile

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****      raise e

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****    File "_home_weewx_skins_Seasons_TFA_hilo_inc.py", line 162

Sep  1 14:15:29 raspberrypi weewx-tfa[6844]: ****  SyntaxError: keyword can't be an expression


 

 Michael

 

 

 

Thomas Keffer

unread,
Sep 5, 2019, 11:55:31 AM9/5/19
to weewx-user
This is a tough problem. I think we're hitting the limits of the Cheetah parser!

Here's the problem. The expression that sets archive_data gets evaluated immediately, resulting in tuples that consist of a string, and a TimeSpanBinder object.

#set $archive_data = [('day', $day), ('week', $week), ('month', $month), ('year', $year), ('rainyear', $rainyear)]
So, later, it interprets an expression like
$archive[1](data_binding='wx_binding')...
as being a call to a TimeSpanBinder, rather than a call to a constructor.
The only way I can think of to get around this is to refactor the archive_data expression so it reads
#set $archive_data = [('day', $day, $day(data_binding='sdr_binding')), ('week', $week, $week(data_binding='sdr_binding')), ('month', $month, $month(data_binding='sdr_binding')), ('year', $year, $year(data_binding='sdr_binding')), ('rainyear', $rainyear, $rainyear(data_binding='sdr_binding'))]
Each tuple now consists of (a string, a plain TimeSpanBinder, and a TimeSpanBinder bound to the sdr_binding data binding) --- what you want.
Now your block looks like

    <tr>

        <td class="label">$obs.label.extraTemp6</td>

        #for $archive in $archive_data

        <td class="data new_row hilo_$archive[0]">

          <span title="$archive[2].extraTemp6.maxtime">

            $archive[2].extraTemp6.max.format(add_label=False)</span><br/>

          <span title="$archive[2].extraTemp6.mintime">

            $archive[2].extraTemp6.min.format(add_label=False)</span>

        </td>

        #end for

        <td class="units">$unit.label.extraTemp6</td>

    </tr>

Hope this helps.
-tk



--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/7ab94a55-f037-4638-9e19-4915baa64c8b%40googlegroups.com.

Michael

unread,
Sep 5, 2019, 2:20:37 PM9/5/19
to weewx-user
Hi Thomas,

it's really great. Your suggestion does exactly what I want it to do.
Many thanks for weewx and also the support here in the forum

Michael
To unsubscribe from this group and stop receiving emails from it, send an email to weewx...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages