I ended up finding a Python function that recurses through any dict and 
nested dict and does a try/except on the value to convert to string. I 
modified that example code to use weeutil.weeutil.to_int(). and am running 
my Highcharts Series data through that function. So far seems to be working 
great! 

I might also look at adding a weeutil.weeutil.to_bool() recursive check as 
well to see if it helps with some other Python ConfigObj to JavaScript 
issues I'm having. Thanks for the tips. 


On Friday, June 7, 2019 at 10:59:54 AM UTC-4, Pat wrote:
>
> That was my concern that nothing was baked into ConfigObj. Thankfully most 
> of the strings are accepted by Highcharts, but there's certain ones like 
> marker: 
> { enabled: false } needs to be false, not a string ("false"). 
> Substituting "false" for integer 0 works, but ConfigObj sets this to string 
> "0". An option like marker, lineWidth, lineWidthPlus, and many more are 
> optional non-coded user-controlled options and I don't have an easy way to 
> intercept each one and to convert to integer. Simply because the generator 
> accepts all highchart series configs without me needed to add more 
> overhead. 
>
> I may have to get fancy with JavaScript and loop through the series Object 
> keys and convert any value to a number that can be converted. 
>
>
> On Friday, June 7, 2019 at 10:55:34 AM UTC-4, Tom Keffer wrote:
>>
>> Unfortunately, no. Without the validator, everything ConfigObj returns is 
>> a string.
>>
>> However, there are some useful utility functions in weeutil.weeutil: 
>> to_int(), to_float(), and to_bool(), which take care of possible 'None' 
>> values. They are sprinkled throughout WeeWX, wherever a conversion needs to 
>> take place.
>>
>> -tk
>>
>> On Fri, Jun 7, 2019 at 7:46 AM Pat <[email protected]> wrote:
>>
>>> Not really weewx-centric but since weewx uses configobj, I have a 
>>> question that you may have come across before. In Belchertown skin 1.0 I've 
>>> adopted the ImageGenerator to fork and build it out for the 
>>> HighchartGenerator. The end result in my fork is the creation of a JSON 
>>> file (instead of an image). 
>>>
>>> Certain config items need to be integers but it seems that ConfigObj is 
>>> forcing strings. I've tried the integer() option 
>>> <https://configobj.readthedocs.io/en/latest/configobj.html#default-values>, 
>>> but that seems related to the Validator 
>>> <https://configobj.readthedocs.io/en/latest/configobj.html#validation> 
>>> which I'm not using because I'd have a mile-long validation ini full of 
>>> Highcharts defaults which I also don't want to manage.
>>>
>>> Is there a way to have ConfigObj force integer if the value is an 
>>> integer? 
>>>
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "weewx-development" 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-development/bee63ee9-1e8b-4b94-8e49-92ca0a70d19a%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/weewx-development/bee63ee9-1e8b-4b94-8e49-92ca0a70d19a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-development" 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-development/c6c1d873-7eb0-4953-9c45-63ac3d175d91%40googlegroups.com.

Reply via email to