[meteofrance] fix #1431, call the url that retrieve all the search results
This commit is contained in:
parent
e5601f9476
commit
8ca5c619c5
2 changed files with 21 additions and 21 deletions
|
|
@ -21,11 +21,7 @@
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser
|
from weboob.tools.browser import BaseBrowser
|
||||||
from weboob.tools.json import json as simplejson
|
from .pages.meteo import WeatherPage, SearchCitiesPage
|
||||||
from weboob.capabilities.weather import City
|
|
||||||
|
|
||||||
from .pages.meteo import WeatherPage
|
|
||||||
import re
|
|
||||||
|
|
||||||
__all__ = ['MeteofranceBrowser']
|
__all__ = ['MeteofranceBrowser']
|
||||||
|
|
||||||
|
|
@ -34,29 +30,23 @@ class MeteofranceBrowser(BaseBrowser):
|
||||||
DOMAIN = 'www.meteofrance.com'
|
DOMAIN = 'www.meteofrance.com'
|
||||||
PROTOCOL = 'http'
|
PROTOCOL = 'http'
|
||||||
ENCODING = 'utf-8'
|
ENCODING = 'utf-8'
|
||||||
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
|
||||||
WEATHER_URL = '{0}://{1}/previsions-meteo-france/{{city_name}}/{{city_id}}'.format(PROTOCOL, DOMAIN)
|
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}}'\
|
CITY_SEARCH_URL = 'http://www.meteofrance.com/recherche/resultats'
|
||||||
.format(PROTOCOL, DOMAIN)
|
|
||||||
PAGES = {
|
PAGES = {
|
||||||
WEATHER_URL.format(city_id=".*", city_name=".*"): WeatherPage,
|
WEATHER_URL.format(city_id=".*", city_name=".*"): WeatherPage,
|
||||||
|
CITY_SEARCH_URL: SearchCitiesPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
BaseBrowser.__init__(self, *args, **kwargs)
|
BaseBrowser.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def iter_city_search(self, pattern):
|
def iter_city_search(self, pattern):
|
||||||
searchurl = self.CITY_SEARCH_URL.format(city_pattern=urllib.quote_plus(pattern.encode('utf-8')))
|
datas = {'facet': 'previsions',
|
||||||
response = self.openurl(searchurl)
|
'search-type': 'previsions',
|
||||||
return self.parse_cities_result(response)
|
'query': pattern}
|
||||||
|
self.location(self.CITY_SEARCH_URL, data=urllib.urlencode(datas))
|
||||||
def parse_cities_result(self, datas):
|
assert self.is_on_page(SearchCitiesPage)
|
||||||
cities = simplejson.loads(datas.read(), self.ENCODING)
|
return self.page.iter_cities()
|
||||||
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
|
|
||||||
|
|
||||||
def iter_forecast(self, city_id):
|
def iter_forecast(self, city_id):
|
||||||
mcity = self.iter_city_search(city_id).next()
|
mcity = self.iter_city_search(city_id).next()
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,24 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.capabilities.weather import Forecast, Current
|
from weboob.capabilities.weather import Forecast, Current, City
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
__all__ = ['WeatherPage']
|
__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):
|
class WeatherPage(BasePage):
|
||||||
def get_temp_without_unit(self, temp_str):
|
def get_temp_without_unit(self, temp_str):
|
||||||
# It seems that the mechanize module give us some old style
|
# It seems that the mechanize module give us some old style
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue