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:
parent
714b1be9ad
commit
14ac02bac5
4 changed files with 78 additions and 43 deletions
21
weboob/backends/meteofrance/__init__.py
Normal file
21
weboob/backends/meteofrance/__init__.py
Normal 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']
|
||||||
|
|
@ -40,8 +40,11 @@ class MeteofranceBackend(BaseBackend, ICapWeather):
|
||||||
def create_default_browser(self):
|
def create_default_browser(self):
|
||||||
return self.create_browser()
|
return self.create_browser()
|
||||||
|
|
||||||
def get_weather(self, city_id):
|
def get_current(self, city_id):
|
||||||
return self.browser.get_weather(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):
|
def iter_city_search(self, pattern):
|
||||||
return self.browser.iter_city_search(pattern.replace(' ','+'))
|
return self.browser.iter_city_search(pattern.replace(' ','+'))
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ class MeteofranceBrowser(BaseBrowser):
|
||||||
PAGES = {
|
PAGES = {
|
||||||
WEATHER_URL.format(cityid=".*") : WeatherPage,
|
WEATHER_URL.format(cityid=".*") : WeatherPage,
|
||||||
CITY_SEARCH_URL.format(city_pattern=".*") : CityPage,
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
BaseBrowser.__init__(self, *args, **kwargs)
|
BaseBrowser.__init__(self, *args, **kwargs)
|
||||||
|
|
@ -50,10 +51,16 @@ class MeteofranceBrowser(BaseBrowser):
|
||||||
else:
|
else:
|
||||||
# Case 2: there is only one result, and the website send directly
|
# Case 2: there is only one result, and the website send directly
|
||||||
# the browser on the forecast page:
|
# 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))
|
self.location(self.WEATHER_URL.format(cityid=city_id))
|
||||||
|
|
||||||
assert self.is_on_page(WeatherPage)
|
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()
|
||||||
|
|
|
||||||
|
|
@ -20,49 +20,53 @@
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.capabilities.weather import ICapWeather, Forecast, Current, City
|
from weboob.capabilities.weather import ICapWeather, Forecast, Current, City
|
||||||
|
|
||||||
import pdb
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['WeatherPage', 'CityResultPage']
|
__all__ = ['WeatherPage', 'CityResultPage']
|
||||||
|
|
||||||
|
|
||||||
class WeatherPage(BasePage):
|
class WeatherPage(BasePage):
|
||||||
def get_weather(self):
|
def iter_forecast(self):
|
||||||
return "5"
|
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):
|
def get_city(self):
|
||||||
# return "6"
|
"""Return the city from the forecastpage
|
||||||
# for table in self.document.getiterator('table'):
|
"""
|
||||||
# if table.attrib.get('id','') != 'searchResult':
|
for div in self.document.getiterator('div'):
|
||||||
# raise Exception('You''re in serious troubles!')
|
if div.attrib.has_key("class") and div.attrib.get("class") == "choix":
|
||||||
# else:
|
for strong in div.getiterator("strong"):
|
||||||
# for tr in table.getiterator('tr'):
|
city_name=strong.text +" "+ strong.tail.replace("(","").replace(")","")
|
||||||
# if tr.get('class','') != "header":
|
city_id=self.url.split("/")[-1]
|
||||||
# td = tr.getchildren()[1]
|
|
||||||
# div = td.getchildren()[0]
|
|
||||||
# link = div.find('a').attrib['href']
|
|
||||||
# title = div.find('a').text
|
|
||||||
# idt = link.split('/')[2]
|
|
||||||
|
|
||||||
# a = td.getchildren()[1]
|
return City( city_id, city_name)
|
||||||
# url = a.attrib['href']
|
|
||||||
|
|
||||||
# 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):
|
class CityPage(BasePage):
|
||||||
def iter_city_search(self):
|
def iter_city_search(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue