simplify and factorize code, remove dead code, follow conventions, use new-style classes
This commit is contained in:
parent
55a1574df5
commit
f1b3264a67
28 changed files with 202 additions and 251 deletions
|
|
@ -15,6 +15,7 @@
|
|||
# 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
|
||||
|
||||
|
|
@ -31,10 +32,6 @@ class MeteofranceBackend(BaseBackend, ICapWeather):
|
|||
VERSION = '0.5'
|
||||
DESCRIPTION = 'Get forecasts from the MeteoFrance website'
|
||||
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):
|
||||
|
|
|
|||
|
|
@ -31,14 +31,16 @@ class MeteofranceBrowser(BaseBrowser):
|
|||
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)
|
||||
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,
|
||||
"http://france.meteofrance.com/france/meteo.*" : WeatherPage
|
||||
}
|
||||
WEATHER_URL.format(cityid=".*"): WeatherPage,
|
||||
CITY_SEARCH_URL.format(city_pattern=".*"): CityPage,
|
||||
'http://france.meteofrance.com/france/accueil/resultat.*': CityPage,
|
||||
'http://france.meteofrance.com/france/meteo.*': WeatherPage,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from weboob.capabilities.weather import Forecast, Current, City
|
|||
|
||||
import datetime
|
||||
|
||||
|
||||
__all__ = ['WeatherPage', 'CityPage']
|
||||
|
||||
|
||||
|
|
@ -60,16 +61,15 @@ class WeatherPage(BasePage):
|
|||
mdate = datetime.datetime.now()
|
||||
return Current(mdate, temp, mtxt, "C")
|
||||
|
||||
|
||||
def get_city(self):
|
||||
"""Return the city from the forecastpage
|
||||
"""
|
||||
Return the city from the forecastpage.
|
||||
"""
|
||||
for div in self.document.getiterator('div'):
|
||||
if div.attrib.has_key("class") and div.attrib.get("class") == "choix":
|
||||
for strong in div.getiterator("strong"):
|
||||
city_name=strong.text +" "+ strong.tail.replace("(","").replace(")","")
|
||||
city_id=self.url.split("/")[-1]
|
||||
|
||||
return City(city_id, city_name)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue