Adding a new Backend for the meteofrance website. This is only an Alpha version
Signed-off-by: Cedric <cedric@aiur.fr>
This commit is contained in:
parent
bd12ead317
commit
714b1be9ad
4 changed files with 209 additions and 0 deletions
59
weboob/backends/meteofrance/browser.py
Normal file
59
weboob/backends/meteofrance/browser.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Julien Veyssier
|
||||
#
|
||||
# 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 weboob.tools.browser import BaseBrowser
|
||||
|
||||
#from .pages.index import
|
||||
from .pages.meteo import WeatherPage, CityPage
|
||||
|
||||
|
||||
__all__ = ['MeteofranceBrowser']
|
||||
|
||||
|
||||
class MeteofranceBrowser(BaseBrowser):
|
||||
DOMAIN = 'france.meteofrance.com'
|
||||
PROTOCOL = 'http'
|
||||
ENCODING = 'utf-8'
|
||||
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
||||
WEATHER_URL = "{0}://{1}/france/meteo?PREVISIONS_PORTLET.path=previsionsville/{{cityid}}".format(PROTOCOL, DOMAIN)
|
||||
CITY_SEARCH_URL="{0}://{1}/france/accueil/resultat?RECHERCHE_RESULTAT_PORTLET.path=rechercheresultat&query={{city_pattern}}&type=PREV_FRANCE&satellite=france".format(PROTOCOL, DOMAIN)
|
||||
PAGES = {
|
||||
WEATHER_URL.format(cityid=".*") : WeatherPage,
|
||||
CITY_SEARCH_URL.format(city_pattern=".*") : CityPage,
|
||||
"http://france.meteofrance.com/france/accueil/resultat.*" : CityPage
|
||||
}
|
||||
def __init__(self, *args, **kwargs):
|
||||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
|
||||
def iter_city_search(self, pattern):
|
||||
searchurl = self.CITY_SEARCH_URL.format( city_pattern=pattern )
|
||||
self.location(searchurl)
|
||||
|
||||
if self.is_on_page(CityPage):
|
||||
# Case 1: there are multiple results for the pattern:
|
||||
return self.page.iter_city_search()
|
||||
else:
|
||||
# Case 2: there is only one result, and the website send directly
|
||||
# the browser on the forecast page:
|
||||
raise NotImplementedError("Will come soon")
|
||||
|
||||
def get_weather(self, city_id):
|
||||
self.location(self.WEATHER_URL.format(cityid=city_id))
|
||||
|
||||
assert self.is_on_page(WeatherPage)
|
||||
return self.page.get_weather()
|
||||
Loading…
Add table
Add a link
Reference in a new issue