using Weboob.do()

This commit is contained in:
Romain Bignon 2010-04-29 15:50:11 +02:00
commit d900375a39

View file

@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
from weboob import CallErrors
from weboob.capabilities.weather import ICapWeather, CityNotFound from weboob.capabilities.weather import ICapWeather, CityNotFound
from weboob.tools.application import ConsoleApplication from weboob.tools.application import ConsoleApplication
@ -37,8 +38,7 @@ class WetBoobs(ConsoleApplication):
print '| ID | Name |' print '| ID | Name |'
print '+--------------------------------+---------------------------------------------+' print '+--------------------------------+---------------------------------------------+'
count = 0 count = 0
for backend in self.weboob.iter_backends(): for backend, city in self.weboob.do('iter_city_search', pattern):
for city in backend.iter_city_search(pattern):
print u'| %-31s| %-44s|' % (city.city_id, city.name) print u'| %-31s| %-44s|' % (city.city_id, city.name)
count += 1 count += 1
print "+--------------------------------'---------------------------------------------+" print "+--------------------------------'---------------------------------------------+"
@ -51,14 +51,17 @@ class WetBoobs(ConsoleApplication):
print '| Temperature | Text |' print '| Temperature | Text |'
print '+-------------+----------------------------------------------------------------+' print '+-------------+----------------------------------------------------------------+'
found = 0 found = 0
for backend in self.weboob.iter_backends():
try: try:
current = backend.get_current(city) for backend, current in self.weboob.do('get_current', city):
print u'| %-12s| %-63s|' % (u'%d °%s' % (current.temp, current.unit), current.text) print u'| %-12s| %-63s|' % (u'%d °%s' % (current.temp, current.unit), current.text)
found = 1 found = 1
except CityNotFound: except CallErrors, e:
for error in e:
if isinstance(error, CityNotFound):
if not found: if not found:
found = -1 found = -1
else:
raise error
if found < 0: if found < 0:
print "| -- | City not found |" print "| -- | City not found |"
print "+-------------'----------------------------------------------------------------+" print "+-------------'----------------------------------------------------------------+"
@ -69,17 +72,20 @@ class WetBoobs(ConsoleApplication):
print '| Date | Min | Max | Text |' print '| Date | Min | Max | Text |'
print '+-------------+-------+-------+------------------------------------------------+' print '+-------------+-------+-------+------------------------------------------------+'
found = 0 found = 0
for backend in self.weboob.iter_backends():
try: try:
for f in backend.iter_forecast(city): for backend, f in self.weboob.do('iter_forecast', city):
found = 1 found = 1
print u'| %-12s|%6s |%6s | %-47s|' % (f.date, print u'| %-12s|%6s |%6s | %-47s|' % (f.date,
u'%d °%s' % (f.low, f.unit), u'%d °%s' % (f.low, f.unit),
u'%d °%s' % (f.high, f.unit), u'%d °%s' % (f.high, f.unit),
f.text) f.text)
except CityNotFound: except CallErrors, e:
for error in e:
if isinstance(error, CityNotFound):
if not found: if not found:
found = -1 found = -1
else:
raise error
if found < 0: if found < 0:
print "| -- --- ---- | -- | -- | City not found |" print "| -- --- ---- | -- | -- | City not found |"
print "+-------------'-------'-------'------------------------------------------------+" print "+-------------'-------'-------'------------------------------------------------+"