[meteofrance] fix #1431, call the url that retrieve all the search results

This commit is contained in:
Bezleputh 2014-07-22 10:55:45 +02:00
commit 8ca5c619c5
2 changed files with 21 additions and 21 deletions

View file

@ -21,11 +21,7 @@
import urllib
from weboob.tools.browser import BaseBrowser
from weboob.tools.json import json as simplejson
from weboob.capabilities.weather import City
from .pages.meteo import WeatherPage
import re
from .pages.meteo import WeatherPage, SearchCitiesPage
__all__ = ['MeteofranceBrowser']
@ -34,29 +30,23 @@ class MeteofranceBrowser(BaseBrowser):
DOMAIN = 'www.meteofrance.com'
PROTOCOL = 'http'
ENCODING = 'utf-8'
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
WEATHER_URL = '{0}://{1}/previsions-meteo-france/{{city_name}}/{{city_id}}'.format(PROTOCOL, DOMAIN)
CITY_SEARCH_URL = '{0}://{1}/mf3-rpc-portlet/rest/lieu/facet/previsions/search/{{city_pattern}}'\
.format(PROTOCOL, DOMAIN)
CITY_SEARCH_URL = 'http://www.meteofrance.com/recherche/resultats'
PAGES = {
WEATHER_URL.format(city_id=".*", city_name=".*"): WeatherPage,
CITY_SEARCH_URL: SearchCitiesPage,
}
def __init__(self, *args, **kwargs):
BaseBrowser.__init__(self, *args, **kwargs)
def iter_city_search(self, pattern):
searchurl = self.CITY_SEARCH_URL.format(city_pattern=urllib.quote_plus(pattern.encode('utf-8')))
response = self.openurl(searchurl)
return self.parse_cities_result(response)
def parse_cities_result(self, datas):
cities = simplejson.loads(datas.read(), self.ENCODING)
re_id = re.compile('\d{5}', re.DOTALL)
for city in cities:
if re_id.match(city['codePostal']):
mcity = City(int(city['codePostal']), u'%s' % city['slug'])
yield mcity
datas = {'facet': 'previsions',
'search-type': 'previsions',
'query': pattern}
self.location(self.CITY_SEARCH_URL, data=urllib.urlencode(datas))
assert self.is_on_page(SearchCitiesPage)
return self.page.iter_cities()
def iter_forecast(self, city_id):
mcity = self.iter_city_search(city_id).next()

View file

@ -20,14 +20,24 @@
from weboob.tools.browser import BasePage
from weboob.capabilities.weather import Forecast, Current
from weboob.capabilities.weather import Forecast, Current, City
import datetime
import re
__all__ = ['WeatherPage']
class SearchCitiesPage(BasePage):
def iter_cities(self):
list = self.document.getroot().xpath('//ul[@class="list-style-1"]/li/a')
for a in list:
m = re.search('/.*/(.*)/(\d{5})', a.attrib.get('href'))
if m:
mcity = City(int(m.group(2)), u'%s' % m.group(1))
yield mcity
class WeatherPage(BasePage):
def get_temp_without_unit(self, temp_str):
# It seems that the mechanize module give us some old style