Unicode/UTF-8 characters no longer translating

90 views
Skip to first unread message

Colin Larsen

unread,
Jun 17, 2020, 11:00:30 PM6/17/20
to weewx-user
Hi all

As part of my installation I have FilePile grabbing some air quality data. To get the proper unit formatting for micrograms per cubic meter I use the units line below - 

weewx.units.default_unit_label_dict['microgramm_per_meter_cubic']  = ' \xce\xbcg/m\xc2\xb3'

which was working fine until (I think) the update to either Weewx 4.0 or Python 3. The output now looks like this ......

CO2 level is 4904 ppm, AQM2.5 is 2.4 μg/m³, AQM10.0 is 2.8 μg/m³, Air Quality Index is 10

Any help appreciated

Colin

gjr80

unread,
Jun 17, 2020, 11:28:08 PM6/17/20
to weewx-user
Hi,

If you are using WeeWX 4.x you should be able to do away with that line as WeeWX now includes an (appropriate) entry for microgram_per_meter_cubed in weewx.units.default_unit_label_dict. https://github.com/weewx/weewx/blob/master/bin/weewx/units.py#L489 refers.

Gary

Colin Larsen

unread,
Jun 17, 2020, 11:37:32 PM6/17/20
to weewx-user
Thanks gery

I've edited my FilePile.py to change all of my microgramm_per_meter_cubic to microgram_per_meter_cubed and removed the other line, will see how that goes.

Cheers
Colin

--
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/edf04bf5-6686-4d28-9f6f-a8eea40bee66o%40googlegroups.com.

Colin Larsen

unread,
Jun 17, 2020, 11:37:59 PM6/17/20
to weewx-user
Sorry, typo -- Gary :)

gjr80

unread,
Jun 17, 2020, 11:44:30 PM6/17/20
to weewx-user
Ha, did not even notice!

Gary

Colin Larsen

unread,
Jun 18, 2020, 12:02:49 AM6/18/20
to weewx-user
Whew!

So interestingly that hasn't changed the results published on the web page, so I wonder if this is a skin problem not a Weewx one? I'm using the Belchertown skin (it's the latest beta but the latest production release also displayed the same) The 'about.inc' file has the following line in it

"At $current.dateTime the following AQI data has been recorded. CO2 level is $current.AQICO2, AQM2.5 is $current.AQI25, AQM10.0 is $current.AQI100, Air Quality Index is $current.AQIIndex"

The data is fine, it's just the units that haven't translated. Unfortunately this is something I rarely look at so I didn't see which update caused the change


On Thu, 18 Jun 2020 at 15:44, gjr80 <gjrod...@gmail.com> wrote:
Ha, did not even notice!

Gary

--
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.

Colin Larsen

unread,
Jun 18, 2020, 12:32:00 AM6/18/20
to weewx-user
Or it would help if I edited the right version of the file! My bad, time to tidy up the file system a bit.

Cheers

Tom Keffer

unread,
Jun 20, 2020, 2:29:18 PM6/20/20
to weewx-user
It looks like you sorted this problem out yourself, but I thought I'd explain why your code was not working.

Under Python 3, all strings are unicode. So, the line

weewx.units.default_unit_label_dict['microgramm_per_meter_cubic']  = ' \xce\xbcg/m\xc2\xb3'

creates a unicode string with code points 32. 206, 188, 103, etc., which corresponds to characters 'μg/m³'. The key here is that your code is specifying code points, not UTF encodings. 

If you want to use UTF encodings, then you must decode them into unicode. So, it becomes:

weewx.units.default_unit_label_dict['microgramm_per_meter_cubic']  = b' \xce\xbcg/m\xc2\xb3'.decode()

The right hand side is now a byte string, which gets decoded into unicode.

-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.

Colin Larsen

unread,
Jun 20, 2020, 3:12:46 PM6/20/20
to weewx-user
Ah, that's brilliant, thanks Tom

Cheers
Colin

Reply all
Reply to author
Forward
0 new messages