From afd26e29fc36233419bb6324411064a9fe817de4 Mon Sep 17 00:00:00 2001 From: Vincent A Date: Fri, 30 Apr 2021 22:45:12 +0200 Subject: [PATCH] [lesterrains] modernize --- modules/lesterrains/__init__.py | 8 +++---- modules/lesterrains/browser.py | 32 +++++++++++++------------ modules/lesterrains/module.py | 16 ++++++------- modules/lesterrains/pages.py | 41 +++++++++++++++++---------------- modules/lesterrains/test.py | 15 ++++++------ 5 files changed, 57 insertions(+), 55 deletions(-) diff --git a/modules/lesterrains/__init__.py b/modules/lesterrains/__init__.py index 4862c1f20a..70483b1d64 100644 --- a/modules/lesterrains/__init__.py +++ b/modules/lesterrains/__init__.py @@ -2,20 +2,20 @@ # Copyright(C) 2019 Guntra # -# This file is part of a weboob module. +# This file is part of a woob module. # -# This weboob module is free software: you can redistribute it and/or modify +# This woob module is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# This weboob module is distributed in the hope that it will be useful, +# This woob module 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with this weboob module. If not, see . +# along with this woob module. If not, see . from __future__ import unicode_literals from .module import LesterrainsModule diff --git a/modules/lesterrains/browser.py b/modules/lesterrains/browser.py index 6cf75cacbb..7065ab22be 100644 --- a/modules/lesterrains/browser.py +++ b/modules/lesterrains/browser.py @@ -2,26 +2,28 @@ # Copyright(C) 2019 Guntra # -# This file is part of a weboob module. +# This file is part of a woob module. # -# This weboob module is free software: you can redistribute it and/or modify +# This woob module is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# This weboob module is distributed in the hope that it will be useful, +# This woob module 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with this weboob module. If not, see . +# along with this woob module. If not, see . from __future__ import unicode_literals -from weboob.browser import PagesBrowser, URL -from weboob.browser.filters.standard import CleanText, Lower, Regexp -from weboob.capabilities.housing import (TypeNotSupported, POSTS_TYPES, HOUSE_TYPES) -from weboob.tools.compat import urlencode + +from woob.browser import PagesBrowser, URL +from woob.browser.filters.standard import CleanText, Lower, Regexp +from woob.capabilities.housing import TypeNotSupported, POSTS_TYPES, HOUSE_TYPES +from woob.tools.compat import urlencode + from .pages import CitiesPage, SearchPage, HousingPage @@ -34,14 +36,14 @@ class LesterrainsBrowser(PagesBrowser): RET = { HOUSE_TYPES.LAND: 'Terrain seul' } - cities = URL('/api/get-search.php\?q=(?P.*)', CitiesPage) - search = URL('/index.php\?mode_aff=liste&ongletAccueil=Terrains&(?P.*)&distance=0', SearchPage) + cities = URL(r'/api/get-search.php\?q=(?P.*)', CitiesPage) + search = URL(r'/index.php\?mode_aff=liste&ongletAccueil=Terrains&(?P.*)&distance=0', SearchPage) housing = URL( - '/index.php\?page=terrains&mode_aff=un_terrain&idter=(?P<_id>\d+).*', - '/index.php\?page=terrains&mode_aff=maisonterrain&idter=(?P<_id>\d+).*', + r'/index.php\?page=terrains&mode_aff=un_terrain&idter=(?P<_id>\d+).*', + r'/index.php\?page=terrains&mode_aff=maisonterrain&idter=(?P<_id>\d+).*', HousingPage ) - + def get_cities(self, pattern): return self.cities.open(city=pattern).get_cities() @@ -52,7 +54,7 @@ def _get_departement(city): def _get_ville(city): return city.split(';')[1] - + for city in cities: query = urlencode({ "departement": _get_departement(city), @@ -66,4 +68,4 @@ def _get_ville(city): yield house def get_housing(self, _id, housing=None): - return self.housing.go(_id = _id).get_housing(obj=housing) \ No newline at end of file + return self.housing.go(_id=_id).get_housing(obj=housing) diff --git a/modules/lesterrains/module.py b/modules/lesterrains/module.py index 2af318b278..d3bf24f3e7 100644 --- a/modules/lesterrains/module.py +++ b/modules/lesterrains/module.py @@ -2,24 +2,24 @@ # Copyright(C) 2019 Guntra # -# This file is part of a weboob module. +# This file is part of a woob module. # -# This weboob module is free software: you can redistribute it and/or modify +# This woob module is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# This weboob module is distributed in the hope that it will be useful, +# This woob module 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with this weboob module. If not, see . +# along with this woob module. If not, see . from __future__ import unicode_literals -from weboob.tools.backend import Module -from weboob.capabilities.housing import CapHousing +from woob.tools.backend import Module +from woob.capabilities.housing import CapHousing from .browser import LesterrainsBrowser @@ -41,7 +41,7 @@ class LesterrainsModule(Module, CapHousing): MAINTAINER = 'Guntra' EMAIL = 'guntra@example.com' LICENSE = 'LGPLv3+' - VERSION = '1.6' + VERSION = '3.1' BROWSER = LesterrainsBrowser def search_city(self, pattern): @@ -60,4 +60,4 @@ def search_housings(self, query): ) def get_housing(self, housing): - return self.browser.get_housing(housing) \ No newline at end of file + return self.browser.get_housing(housing) diff --git a/modules/lesterrains/pages.py b/modules/lesterrains/pages.py index 61b118c5cc..827eb2b0a5 100644 --- a/modules/lesterrains/pages.py +++ b/modules/lesterrains/pages.py @@ -2,32 +2,33 @@ # Copyright(C) 2019 Guntra # -# This file is part of a weboob module. +# This file is part of a woob module. # -# This weboob module is free software: you can redistribute it and/or modify +# This woob module is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# This weboob module is distributed in the hope that it will be useful, +# This woob module 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with this weboob module. If not, see . +# along with this woob module. If not, see . from __future__ import unicode_literals -from weboob.browser.filters.standard import ( + +from woob.browser.filters.standard import ( CleanDecimal, CleanText, Date, Format, Lower, Regexp, QueryValue ) -from weboob.browser.filters.json import Dict -from weboob.browser.filters.html import Attr, AbsoluteLink -from weboob.browser.elements import ItemElement, ListElement, DictElement, method -from weboob.browser.pages import JsonPage, HTMLPage, pagination -from weboob.capabilities.base import Currency, NotAvailable -from weboob.capabilities.housing import ( +from woob.browser.filters.json import Dict +from woob.browser.filters.html import Attr, AbsoluteLink +from woob.browser.elements import ItemElement, ListElement, DictElement, method +from woob.browser.pages import JsonPage, HTMLPage, pagination +from woob.capabilities.base import Currency, NotAvailable +from woob.capabilities.housing import ( Housing, HousingPhoto, City, POSTS_TYPES, HOUSE_TYPES, ADVERT_TYPES, UTILITIES ) @@ -50,11 +51,10 @@ class get_cities(DictElement): class item(ItemElement): klass = City obj_id = Dict('id') & CleanText() & Lower() - obj_name= Dict('value') & CleanText() + obj_name = Dict('value') & CleanText() class SearchPage(HTMLPage): - @pagination @method class iter_housings(ListElement): @@ -86,14 +86,14 @@ def obj_area(self): min_area = CleanDecimal( Regexp( CleanText('.//div[@class="presentationItem"]/h3'), - 'surface de (\d+) m²', + r'surface de (\d+) m²', default=0 ) )(self) max_area = CleanDecimal( Regexp( CleanText('.//div[@class="presentationItem"]/h3'), - 'à (\d+) m²', + r'à (\d+) m²', default=0 ) )(self) @@ -108,10 +108,11 @@ def obj_area(self): ) obj_currency = Currency.get_currency('€') obj_date = Date( - CleanText( - './/div[@class="presentationItem"]//span[@class="majItem"]', - replace=[("Mise à jour : ", "")]), - default=NotAvailable + CleanText( + './/div[@class="presentationItem"]//span[@class="majItem"]', + replace=[("Mise à jour : ", "")] + ), + default=NotAvailable ) obj_location = CleanText( './/div[@class="presentationItem"]/h2/a/span', @@ -174,7 +175,7 @@ def obj_cost(self): CleanDecimal( CleanText( './td[3]', - replace=[(".","")] + replace=[(".", "")] ) )(land) ) diff --git a/modules/lesterrains/test.py b/modules/lesterrains/test.py index 8554df0f9d..ebb348c325 100644 --- a/modules/lesterrains/test.py +++ b/modules/lesterrains/test.py @@ -2,29 +2,28 @@ # Copyright(C) 2019 Guntra # -# This file is part of a weboob module. +# This file is part of a woob module. # -# This weboob module is free software: you can redistribute it and/or modify +# This woob module is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# This weboob module is distributed in the hope that it will be useful, +# This woob module 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with this weboob module. If not, see . +# along with this woob module. If not, see . from __future__ import unicode_literals -from weboob.capabilities.housing import Query, ADVERT_TYPES, POSTS_TYPES -from weboob.tools.capabilities.housing.housing_test import HousingTest -from weboob.tools.test import BackendTest +from woob.capabilities.housing import Query, ADVERT_TYPES, POSTS_TYPES +from woob.tools.capabilities.housing.housing_test import HousingTest +from woob.tools.test import BackendTest class LesterrainsTest(BackendTest, HousingTest): - MODULE = 'lesterrains' # Fields to be checked for values across all items in housings list FIELDS_ALL_HOUSINGS_LIST = [ -- GitLab