diff --git a/weboob/backends/meteofrance/backend.py b/weboob/backends/meteofrance/backend.py new file mode 100644 index 00000000..fd8d6761 --- /dev/null +++ b/weboob/backends/meteofrance/backend.py @@ -0,0 +1,47 @@ +# -*- 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.capabilities.weather import ICapWeather +from weboob.tools.backend import BaseBackend + +from .browser import MeteofranceBrowser + + +__all__ = ['MeteofranceBackend'] + + +class MeteofranceBackend(BaseBackend, ICapWeather): + NAME = 'meteofrance' + MAINTAINER = 'Cedric D.' + EMAIL = 'cedric@aiur.fr' + VERSION = '0.1' + DESCRIPTION = 'MeteoFrance' + LICENSE = 'GPLv3' + #CONFIG = ValuesDict(Value('domain', label='Domain (example "ssl.what.cd")'), + # Value('protocol', label='Protocol to use', choices=('http', 'https')), + # Value('username', label='Username'), + # Value('password', label='Password', masked=True)) + BROWSER = MeteofranceBrowser + + def create_default_browser(self): + return self.create_browser() + + def get_weather(self, city_id): + return self.browser.get_weather(city_id) + + def iter_city_search(self, pattern): + return self.browser.iter_city_search(pattern.replace(' ','+')) diff --git a/weboob/backends/meteofrance/browser.py b/weboob/backends/meteofrance/browser.py new file mode 100644 index 00000000..62104c88 --- /dev/null +++ b/weboob/backends/meteofrance/browser.py @@ -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() diff --git a/weboob/backends/meteofrance/pages/__init__.py b/weboob/backends/meteofrance/pages/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/weboob/backends/meteofrance/pages/meteo.py b/weboob/backends/meteofrance/pages/meteo.py new file mode 100644 index 00000000..23269b79 --- /dev/null +++ b/weboob/backends/meteofrance/pages/meteo.py @@ -0,0 +1,103 @@ +# -*- 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 BasePage +from weboob.capabilities.weather import ICapWeather, Forecast, Current, City + +import pdb + + +__all__ = ['WeatherPage', 'CityResultPage'] + + +class WeatherPage(BasePage): + def get_weather(self): + return "5" + + + #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] + + # a = td.getchildren()[1] + # 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): + def iter_city_search(self): + for div in self.document.getiterator('div'): + if div.attrib.get('id') == "column1": + for li in div.getiterator('li'): + city_name = li.text_content() + for children in li.getchildren(): + city_id = children.attrib.get("href").split("/")[-1] + mcity = City( city_id, city_name) + yield mcity + + def plop(self): + for div in self.document.getiterator('div'): + if div.attrib.get('id','') == 'column1': + title = div.text.strip() + elif div.attrib.get('class','') == 'download': + url = div.getchildren()[0].attrib.get('href','') + elif div.attrib.get('id','') == 'details': + size = float(div.getchildren()[0].getchildren()[5].text.split('(')[1].split('Bytes')[0]) + if len(div.getchildren()) > 1 \ + and div.getchildren()[1].attrib.get('class','') == 'col2' : + seed = div.getchildren()[1].getchildren()[7].text + leech = div.getchildren()[1].getchildren()[9].text + else: + seed = div.getchildren()[0].getchildren()[24].text + leech = div.getchildren()[0].getchildren()[26].text + elif div.attrib.get('class','') == 'nfo': + description = div.getchildren()[0].text + torrent = Torrent(id, title) + torrent.url = url + torrent.size = size + torrent.seeders = int(seed) + torrent.leechers = int(leech) + torrent.description = description + torrent.files = ['NYI'] + + return torrent