[leboncoin] handle query.type

This commit is contained in:
Bezleputh 2014-09-26 17:33:26 +02:00
commit 695d969682
3 changed files with 10 additions and 12 deletions

View file

@ -17,7 +17,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.browser2 import PagesBrowser, URL from weboob.tools.browser2 import PagesBrowser, URL
from .pages import CityListPage, HousingListPage, HousingPage from .pages import CityListPage, HousingListPage, HousingPage
@ -26,8 +25,8 @@ from .pages import CityListPage, HousingListPage, HousingPage
class LeboncoinBrowser(PagesBrowser): class LeboncoinBrowser(PagesBrowser):
BASEURL = 'http://www.leboncoin.fr' BASEURL = 'http://www.leboncoin.fr'
city = URL('ajax/location_list.html\?city=(?P<city>.*)&zipcode=(?P<zip>.*)', CityListPage) city = URL('ajax/location_list.html\?city=(?P<city>.*)&zipcode=(?P<zip>.*)', CityListPage)
search = URL('ventes_immobilieres/offres/ile_de_france/occasions/\?ps=(?P<ps>.*)&pe=(?P<pe>.*)&ros=(?P<ros>.*)&location=(?P<location>.*)&sqs=(?P<sqs>.*)&sqe=(?P<sqe>.*)&ret=(?P<ret>.*)', search = URL('(?P<type>.*)/offres/ile_de_france/occasions/\?ps=(?P<ps>.*)&pe=(?P<pe>.*)&ros=(?P<ros>.*)&location=(?P<location>.*)&sqs=(?P<sqs>.*)&sqe=(?P<sqe>.*)&ret=(?P<ret>.*)',
'ventes_immobilieres/offres/ile_de_france/occasions/\?.*', '(ventes_immobilieres|locations)/offres/ile_de_france/occasions/\?.*',
HousingListPage) HousingListPage)
housing = URL('ventes_immobilieres/(?P<_id>.*).htm', HousingPage) housing = URL('ventes_immobilieres/(?P<_id>.*).htm', HousingPage)
@ -42,13 +41,13 @@ class LeboncoinBrowser(PagesBrowser):
return self.city.go(city=city, zip=zip_code).get_cities() return self.city.go(city=city, zip=zip_code).get_cities()
def search_housings(self, type, cities, nb_rooms, area_min, area_max, cost_min, cost_max, ret): def search_housings(self, type, cities, nb_rooms, area_min, area_max, cost_min, cost_max, ret):
# print type achat ou location
return self.search.go(location=cities, return self.search.go(location=cities,
ros=nb_rooms, ros=nb_rooms,
sqs=area_min, sqs=area_min,
sqe=area_max, sqe=area_max,
ps=cost_min, ps=cost_min,
pe=cost_max, pe=cost_max,
type=type,
ret=ret).get_housing_list() ret=ret).get_housing_list()
def get_housing(self, _id): def get_housing(self, _id):

View file

@ -73,7 +73,10 @@ class LeboncoinModule(Module, CapHousing):
if len(ret) == 0: if len(ret) == 0:
return list() return list()
_type = query.TYPE_RENT if query.type is None else query.type _type = 'ventes_immobilieres'
if query.type == Query.TYPE_RENT:
_type = 'locations'
nb_rooms = '' if not query.nb_rooms else query.nb_rooms nb_rooms = '' if not query.nb_rooms else query.nb_rooms
area_min = '' if not query.area_min else query.area_min area_min = '' if not query.area_min else query.area_min
area_max = '' if not query.area_max else query.area_max area_max = '' if not query.area_max else query.area_max

View file

@ -50,7 +50,7 @@ class HousingListPage(HTMLPage):
class item(ItemElement): class item(ItemElement):
klass = Housing klass = Housing
obj_id = Regexp(Link('.'), 'http://www.leboncoin.fr/ventes_immobilieres/(.*).htm') obj_id = Regexp(Link('.'), 'http://www.leboncoin.fr/(ventes_immobilieres|locations)/(.*).htm', '\\2')
obj_title = CleanText('./div[@class="lbc"]/div/div[@class="title"]') obj_title = CleanText('./div[@class="lbc"]/div/div[@class="title"]')
obj_cost = CleanDecimal('./div[@class="lbc"]/div/div[@class="price"]', obj_cost = CleanDecimal('./div[@class="lbc"]/div/div[@class="price"]',
replace_dots=(',', '.'), replace_dots=(',', '.'),
@ -115,12 +115,8 @@ class HousingPage(HTMLPage):
obj_area = Env('area') obj_area = Env('area')
def obj_date(self): def obj_date(self):
sender = CleanText('//div[@class="upload_by"]/a')(self) _date = Regexp(CleanText('//div[@class="upload_by"]', replace=[(u'à', '')]),
_date = CleanText('//div[@class="upload_by"]', '.*- Mise en ligne le (.*).')(self)
replace=[('- Mise en ligne le ', ''),
(sender, ''),
(u'à', ''),
(u'.', '')])(self)
for fr, en in DATE_TRANSLATE_FR: for fr, en in DATE_TRANSLATE_FR:
_date = fr.sub(en, _date) _date = fr.sub(en, _date)