[weboob] [PATCH v2 1/1] wetboobs: added module ilmatieteenlaitos

Matthieu Weber mweber+weboob at free.fr
Sun Feb 8 19:22:34 CET 2015

On Sun 08.02.2015 at 03:51:33PM +0100, Romain Bignon wrote:
> Hi,
> On 06/Feb - 21:16, Matthieu Weber wrote:
> > ---
> >  modules/ilmatieteenlaitos/__init__.py |   23 ++++++++++++++++
> >  modules/ilmatieteenlaitos/browser.py  |   43 +++++++++++++++++++++++++++++
> >  modules/ilmatieteenlaitos/favicon.png |  Bin 0 -> 2213 bytes
> >  modules/ilmatieteenlaitos/module.py   |   49 +++++++++++++++++++++++++++++++++
> >  modules/ilmatieteenlaitos/pages.py    |   47 ++++++++++++++++++-------------
> >  modules/ilmatieteenlaitos/test.py     |   36 ++++++++++++++++++++++++
> >  weboob/capabilities/weather.py        |   10 +++----
> >  7 files changed, 184 insertions(+), 24 deletions(-)
> I've merged your patch, except changes in weather.py as I would like
> explanations about it.

The changes in class Temperature are cosmetic; typographical rules
require a space between the value and the degree as a unit of
temperature (i.e., 20°C is incorrect, 20 °C is correct), while there is
no space between the value of an angle and the degree as an unit of
angle (i.e., 20° is correct, while 20 ° is incorrect).

Regarding class Current, it appears that the Current object is first
initialized with no parameters, and the values are filled in afterwards.
However, since "date" defaults to emtpy string but the type is checked
during assignment, the "current" operation in wetboobs fails,
complaining about the wrong type ("ValueError: Value for "date" needs to
be of type (<type 'datetime.date'>, <type 'datetime.datetime'>), not
<type 'str'>"). Arguably, setting the default value of "date" to None
would have been a smarter change. I noticed this bug when experimenting
with the meteofrance module (which I shamelessly used as a model for
ilmatieteenlaitos) and this is how I got around it.

This bug can be reproduced by checking out 45de52d, activating
"meteofrance" and running:
  tools/local_run.sh wetboobs --debug current 75010 at meteofrance

The result is:

Bug(meteofrance): Value for "date" needs to be of type (<type 'datetime.date'>, <type 'datetime.datetime'>), not <type 'str'>
Traceback (most recent call last):
  File "/home/mweber/space/src/weboob/weboob/core/bcall.py", line 83, in backend_process
    result = function(backend, *args, **kwargs)
  File "/home/mweber/space/src/weboob/weboob/tools/application/base.py", line 308, in _do_complete
    res = getattr(backend, function)(*args, **kwargs)
  File "/home/mweber/space/src/weboob/modules/meteofrance/module.py", line 40, in get_current
    return self.browser.get_current(self.get_city(city_id))
  File "/home/mweber/space/src/weboob/modules/meteofrance/browser.py", line 38, in get_current
    return self.weather.go(city_id=city.id, city_name=city.name).get_current()
  File "/home/mweber/space/src/weboob/weboob/browser/elements.py", line 47, in inner
    return klass(self)(*args, **kwargs)
  File "/home/mweber/space/src/weboob/weboob/browser/elements.py", line 245, in __call__
    for obj in self:
  File "/home/mweber/space/src/weboob/weboob/browser/elements.py", line 254, in __iter__
    self.obj = self.build_object()
  File "/home/mweber/space/src/weboob/weboob/browser/elements.py", line 239, in build_object
    return self.klass()
  File "/home/mweber/space/src/weboob/weboob/capabilities/weather.py", line 90, in __init__
    self.date = date
  File "/home/mweber/space/src/weboob/weboob/capabilities/base.py", line 443, in __setattr__
    name, actual_types, type(value)))
ValueError: Value for "date" needs to be of type (<type 'datetime.date'>, <type 'datetime.datetime'>), not <type 'str'>

There may be an even better fix, I don't know (like not instanciating an
emtpy Current object at all?). The instanciation of Current is burried
deep in metaprogramming, and I was rather focusing on getting my module
working. The bottom line is, without this change, both meteofrance and
ilmatieteenlaitos will fail when calling "current".

I hope this was clear :)

 (~._.~)            Matthieu Weber - mweber at free.fr              (~._.~)
  ( ? )                http://weber.fi.eu.org/                    ( ? ) 
 ()- -()          public key id : 0x85CB340EFCD5E0B3             ()- -()
 (_)-(_) "Humor ist, wenn man trotzdem lacht (Otto J. Bierbaum)" (_)-(_)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <https://lists.symlink.me/pipermail/weboob/attachments/20150208/4ae2ab86/attachment.sig>

More information about the weboob mailing list