display tag for UTC time in skin...?

48 views
Skip to first unread message

hctp...@googlemail.com

unread,
Sep 18, 2021, 4:18:56 AM9/18/21
to weewx-user
Hi,
I set my machine to local time, so $current.dateTime gives me 18.09.2021 10:13.
Is there a tag to get the UTC time (like $current.dateTime .UTC) ?
I want to display both times as I added some sat pictures which includes the UTC time on the picture. To get a better overview I want the UTC time additional in my skin printed out..

Thanks in advance,

Christian

gjr80

unread,
Sep 18, 2021, 5:02:54 AM9/18/21
to weewx-user
There is no tag to display the current dateTime value in UTC/GMT. You will need to manually construct a tag with a little in-template python code. A simple approach is to add something like the following (untested) to your template:

#import time
#set $utc = $time.strftime(‘%d %B %Y %H:%M:%S’, $time.gmtime($current.dateTime.raw))

should allow you to use the tag $utc later in your template to display the current dateTime as UTC. The formatting is controlled by the format string in the $time.gmtime() call. The available format codes can be found here.

There are other more complex approaches depending on your need.

Gary

hctp...@googlemail.com

unread,
Sep 19, 2021, 2:23:12 AM9/19/21
to weewx-user
Gary,

thanks for this code snippet! It would satisfy my needs, but I can't get it to run and didn't see the problem as my skills are limited regarding cheetha and python.
You lines raises this error:

Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: Generate failed with exception '<class 'Cheetah.Parser.ParseError'>'
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/Responsive/index.html.tmpl
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: **** Reason: #012#012Invalid Syntax#012Line 322, column 28 in file /etc/weewx/skins/Responsive/index.html.tmpl#012#012Line|Cheetah Code#012----|-------------------------------------------------------------#012319 |#012320 |## end windrun#012321 |#import time#012322 |#set $utc = $time.strftime(‘%d %B %Y %H:%M:%S’, $time.gmtime($current.dateTime.raw))#012                                ^#012323 |#012324 |  <body>#012325 |    <div class="container-fluid">
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 318, in generate
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      compiled_template = Cheetah.Template.Template(
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 1337, in __init__
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      self._compile(source, file, compilerSettings=compilerSettings)
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 1634, in _compile
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      templateClass = self.compile(source, file,
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 775, in compile
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      compiler.compile()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Compiler.py", line 1802, in compile
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      self._parser.parse()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 1552, in parse
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      self.eatDirective()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 1680, in eatDirective
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      directiveParser()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 2269, in eatSet
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      RVALUE = self.getExpression()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 1261, in getExpression
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      return ''.join(self.getExpressionParts(
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 1220, in getExpressionParts
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      expr = self.getCheetahVar()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 903, in getCheetahVar
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      return self.getCheetahVarBody(plain=plain)
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 907, in getCheetahVarBody
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      return self._compiler.genCheetahVar(self.getCheetahVarNameChunks(),
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 955, in getCheetahVarNameChunks
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      rest = self.getCallArgString()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 1041, in getCallArgString
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      token = self.getPyToken()
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Parser.py", line 606, in getPyToken
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****      raise ParseError(self)
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  Cheetah.Parser.ParseError:
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  Invalid Syntax
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  Line 322, column 28 in file /etc/weewx/skins/Responsive/index.html.tmpl
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  Line|Cheetah Code
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  ----|-------------------------------------------------------------
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  319 |
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  320 |## end windrun
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  321 |#import time
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  322 |#set $utc = $time.strftime(‘%d %B %Y %H:%M:%S’, $time.gmtime($current.dateTime.raw))
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****                                  ^
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  323 |
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  324 |  <body>
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****  325 |    <div class="container-fluid">
Sep 19 08:11:18 weewx weewx[563] ERROR weewx.cheetahgenerator: ****


The formatting seems somehow not to work I think:

$time.strftime(‘%d %B %Y %H:%M:%S’...

If I place this
#set $utc = $time.gmtime($current.dateTime.raw)
in my code I get this output on my html site for $utc:

time.struct_time(tm_year=2021, tm_mon=9, tm_mday=19, tm_hour=6, tm_min=19, tm_sec=0, tm_wday=6, tm_yday=262, tm_isdst=0)

Any hint or idea what could be wrong?

Regards,

Christian

gjr80

unread,
Sep 19, 2021, 4:23:31 AM9/19/21
to weewx-user
Christian,

Check the quotation marks around the format string. If you copied and pasted from the post chances are you have something other than  single/double quotes, python is picky about how you terminate a string, somewhat more so than Google. Unfortunately the new and improved Google groups took away the code blocks.

Gary

hctp...@googlemail.com

unread,
Sep 19, 2021, 4:38:12 AM9/19/21
to weewx-user
Gary,

thanks, ok, changing the single quotes solves the issue and I could add the UTC to my time output additional..

#import time
#set $utc = $time.strftime('%H:%M', $time.gmtime($current.dateTime.raw))

Really odd Google removes code blocks in groups....!? :-O
Now I get the output I want:

19.09.2021 10:31 (08:31 UTC)

Thank you very much.

Regards,

Christian
Reply all
Reply to author
Forward
0 new messages