The meteofrance backend is still basic, but implements all methods and give a correct result.

Signed-off-by: Cedric <cedric@aiur.fr>
This commit is contained in:
Cedric 2010-12-04 16:31:57 +01:00 committed by Romain Bignon
commit 14ac02bac5
4 changed files with 78 additions and 43 deletions

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010 Romain Bignon
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from .backend import MeteofranceBackend
__all__ = ['MeteofranceBackend']

View file

@ -40,8 +40,11 @@ class MeteofranceBackend(BaseBackend, ICapWeather):
def create_default_browser(self):
return self.create_browser()
def get_weather(self, city_id):
return self.browser.get_weather(city_id)
def get_current(self, city_id):
return self.browser.get_current(city_id.split("@")[0])
def iter_forecast(self, city_id):
return self.browser.iter_forecast(city_id.split("@")[0])
def iter_city_search(self, pattern):
return self.browser.iter_city_search(pattern.replace(' ','+'))

View file

@ -35,7 +35,8 @@ class MeteofranceBrowser(BaseBrowser):
PAGES = {
WEATHER_URL.format(cityid=".*") : WeatherPage,
CITY_SEARCH_URL.format(city_pattern=".*") : CityPage,
"http://france.meteofrance.com/france/accueil/resultat.*" : CityPage
"http://france.meteofrance.com/france/accueil/resultat.*" : CityPage,
"http://france.meteofrance.com/france/meteo.*" : WeatherPage
}
def __init__(self, *args, **kwargs):
BaseBrowser.__init__(self, *args, **kwargs)
@ -50,10 +51,16 @@ class MeteofranceBrowser(BaseBrowser):
else:
# Case 2: there is only one result, and the website send directly
# the browser on the forecast page:
raise NotImplementedError("Will come soon")
return self.page.get_city()
def get_weather(self, city_id):
def iter_forecast(self, city_id):
self.location(self.WEATHER_URL.format(cityid=city_id))
assert self.is_on_page(WeatherPage)
return self.page.get_weather()
return self.page.iter_forecast()
def get_current(self, city_id):
self.location(self.WEATHER_URL.format(cityid=city_id))
assert self.is_on_page(WeatherPage)
return self.page.get_current()

View file

@ -20,49 +20,53 @@
from weboob.tools.browser import BasePage
from weboob.capabilities.weather import ICapWeather, Forecast, Current, City
import pdb
import datetime
__all__ = ['WeatherPage', 'CityResultPage']
class WeatherPage(BasePage):
def get_weather(self):
return "5"
def iter_forecast(self):
for div in self.document.getiterator('div'):
if div.attrib.has_key("id") and div.attrib.get('id').find("jour") != -1:
for em in div.getiterator('em'):
templist = em.text_content().split("/")
t_low = templist[0].replace(u"\xb0C", "").strip()
t_high = templist[1].replace(u"\xb0C", "").strip()
break
for strong in div.getiterator("strong"):
mdate = strong.text_content()
break
for img in div.getiterator("img"):
mtxt = img.attrib["title"]
break
yield Forecast(mdate, t_low, t_high, mtxt, "C")
def get_current(self):
for div in self.document.getiterator('div'):
if div.attrib.has_key("id") and div.attrib.get('id') == "blocDetails0":
for em in div.getiterator('em'):
temp = em.text_content()
break
for img in div.getiterator("img"):
mtxt = img.attrib["title"]
break
mdate = str(datetime.datetime.now())
yield Current(mdate, temp, mtxt, "C")
#def iter_forecast(self):
# return "6"
# for table in self.document.getiterator('table'):
# if table.attrib.get('id','') != 'searchResult':
# raise Exception('You''re in serious troubles!')
# else:
# for tr in table.getiterator('tr'):
# if tr.get('class','') != "header":
# td = tr.getchildren()[1]
# div = td.getchildren()[0]
# link = div.find('a').attrib['href']
# title = div.find('a').text
# idt = link.split('/')[2]
def get_city(self):
"""Return the city from the forecastpage
"""
for div in self.document.getiterator('div'):
if div.attrib.has_key("class") and div.attrib.get("class") == "choix":
for strong in div.getiterator("strong"):
city_name=strong.text +" "+ strong.tail.replace("(","").replace(")","")
city_id=self.url.split("/")[-1]
# a = td.getchildren()[1]
# url = a.attrib['href']
return City( city_id, city_name)
# size = td.find('font').text.split(',')[1]
# size = size.split(' ')[2]
# u = size[-3:].replace('i','')
# size = size[:-3]
# seed = tr.getchildren()[2].text
# leech = tr.getchildren()[3].text
# torrent = Torrent(idt,
# title,
# url=url,
# size=self.unit(float(size),u),
# seeders=int(seed),
# leechers=int(leech))
# yield torrent
class CityPage(BasePage):
def iter_city_search(self):