Duncan Webb wrote:
> Jim Duda wrote:
>> Duncan Webb wrote:
>>
>>> Interesting so it look like the data has changed as the code has not
>>> changed for ages.
>>>
>>> Index: src/util/pymetar.py
>>> ===================================================================
>>> --- src/util/pymetar.py (revision 11576)
>>> +++ src/util/pymetar.py (working copy)
>>> @@ -834,7 +834,7 @@
>>>
>>>              elif (header == "Temperature"):
>>>                  f,i,c,i=data.split(None,3)
>>> -                self.Report.tempf=int(f)
>>> +                self.Report.tempf=int(float(f))
>>>                  # The string we have split is "(NN C)", hence the slice
>>>                  self.Report.temp=int(c[1:])
>>>
>> I think we're just peeling the onion here ...
>>
>> Now I get:get:
>>
>> Traceback (most recent call last):
>>   File "/usr/lib/python2.5/site-packages/freevo/plugins/idlebar/weather.py", 
>> line 74, in run
>>     pr = rp.ParseReport(rep)
>>   File "/nfsroot/usr/lib/python2.5/site-packages/freevo/util/pymetar.py", 
>> line 839, in ParseReport
>>     self.Report.temp=int(c[1:])
>> ValueError: invalid literal for int() with base 10: '10.0'
>> ERROR: invalid literal for int() with base 10: '10.0'
> 
> Yes of course. Two ways to solve this make the string a float and let
> the display decide how to display it. Change the parsing of the temp
> data to use a regular expression search/match.
> 
> You may like to try the patches but may need to restore the original
> versions first.

Forget the second patch is was not too cleaver :-(

The attached should be better.

Duncan
Index: src/util/pymetar.py
===================================================================
--- src/util/pymetar.py	(revision 11576)
+++ src/util/pymetar.py	(working copy)
@@ -833,10 +833,11 @@
             # temperature
 
             elif (header == "Temperature"):
-                f,i,c,i=data.split(None,3)
-                self.Report.tempf=int(f)
-                # The string we have split is "(NN C)", hence the slice
-                self.Report.temp=int(c[1:])
+                # data is something like:
+                # '62 F (17 C)' and may have decimal points
+                m = re.search('(\d+).* F.*\((\d+).* C\)', data)
+                self.Report.tempf = int(m.group(1)) if m and len(m.groups()) >= 1 else -1
+                self.Report.temp = int(m.group(2)) if m and len(m.groups()) >= 2 else -1
 
 
             # wind dir and speed
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Freevo-users mailing list
Freevo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-users

Reply via email to