Thanks Tom, I'm sure I had tried that first but it's working now, thanks! [image: Screenshot 2023-05-29 at 12.48.21.png]
On Monday, May 29, 2023 at 11:17:14 AM UTC+1 Tom Keffer wrote: > #if $counter = 1 and $tide.hilo == 'L' <-- error generated here > > You need another equal sign: > > #if $counter == 1 and $tide.hilo == 'L' <-- error generated here > > > On Mon, May 29, 2023 at 1:43 AM 'Rory Gillies' via weewx-user < > [email protected]> wrote: > >> I am trying to do a simple bit of logic to add an empty table row if two >> conditions are met but the Cheetah generator is throwing up a syntax error >> and I can't work out why. This loop generates a table of high tides, but if >> the first tidal event is low tide I don't want the high tide displayed in >> the row as it will be after the low tide. The code is: >> >> <table class="table table-striped text-left"> >> <tr> >> <td><b>Date</b></td></td><td><b>Time >> (local)</b></td><td><b>Height</b></td> >> </tr> >> #set $tides = $forecast.xtides >> #set $counter = 0 >> #for $tide in $tides >> #set $counter = $counter + 1 >> #if $counter = 1 and $tide.hilo == 'L' <-- error generated here >> <tr> >> <td>-</td> >> <td>-</td> >> <td>-</td> >> </tr> >> #else if $counter < 28 >> #set $height=$tide.offset.raw / 3.281 >> #if $tide.hilo == 'H' >> <tr> >> <td>$tide.event_ts.format("%a %d %b")</td> >> <td>$tide.event_ts.format("%H:%M")</td> >> <td> >> #echo '%.2f' % $height >> m </td> >> </tr> >> #end if >> #end if >> #end for >> </table> >> >> And here's the error: >> >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: >> Compilation of template /etc/weewx/skins/neowx-material/almanac.html.tmpl >> failed with exception '<class 'SyntaxError'>' >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> Ignoring template /etc/weewx/skins/neowx-material/almanac.html.tmpl >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> Reason: invalid syntax >> (cheetah__etc_weewx_skins_neowx_material_almanac_html_tmpl_1685348748_259715_51815.py, >> >> line 1247) >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> Traceback (most recent call last): >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 827, in >> compile >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> parseError = genParserErrorFromPythonException( >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 2045, in >> genParserErrorFromPythonException >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> reader = SourceReader(source, filename=filename) >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/SourceReader.py", line 19, >> in __init__ >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> self._srcLen = len(src) >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> TypeError: object of type 'NoneType' has no len() >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> During handling of the above exception, another exception occurred: >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> Traceback (most recent call last): >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/share/weewx/weewx/cheetahgenerator.py", line 332, in generate >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> compiled_template = Cheetah.Template.Template( >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 1337, in >> __init__ >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> self._compile(source, file, compilerSettings=compilerSettings) >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 1634, in >> _compile >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> templateClass = self.compile(source, file, >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 832, in >> compile >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> raise e >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 823, in >> compile >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> co = compile(generatedModuleCode, __file__, 'exec') >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> File >> "cheetah__etc_weewx_skins_neowx_material_almanac_html_tmpl_1685348748_259715_51815.py", >> >> line 1247 >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> if VFFSL(SL,"counter",True) = 1 and VFFSL(SL,"tide.hilo",True) == 'L': >> # generated from line 353, col 21 >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> ^ >> May 29 09:25:48 weather weewx[1049482] ERROR weewx.cheetahgenerator: **** >> SyntaxError: invalid syntax >> >> The code works fine without the empty row logic, and both the $counter >> and $tide.hilo variables are working in the rest of the code, just not when >> I try to use them in a logic statement. >> >> -- >> 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/2ac8df36-f705-46f1-9101-137337784355n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/weewx-user/2ac8df36-f705-46f1-9101-137337784355n%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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/a0f6cfd5-3e7a-431e-9c17-74c36f3636b2n%40googlegroups.com.
