From b6379f7f3765106c04df17f661b6cb788fe5fb48 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Fri, 17 Feb 2012 13:25:06 +0100 Subject: [PATCH] add parameter 'nb_rooms' in queries --- modules/pap/backend.py | 2 +- modules/pap/browser.py | 7 ++- modules/seloger/backend.py | 2 +- modules/seloger/browser.py | 5 ++- modules/seloger/pages.py | 4 +- weboob/applications/flatboob/flatboob.py | 1 + weboob/applications/qflatboob/main_window.py | 11 ++++- weboob/applications/qflatboob/ui/query.ui | 45 ++++++++++++++++++++ weboob/capabilities/housing.py | 1 + 9 files changed, 71 insertions(+), 7 deletions(-) diff --git a/modules/pap/backend.py b/modules/pap/backend.py index 04ece5da..89de162f 100644 --- a/modules/pap/backend.py +++ b/modules/pap/backend.py @@ -41,7 +41,7 @@ class PapBackend(BaseBackend, ICapHousing): return list() with self.browser: - return self.browser.search_housings(cities, + return self.browser.search_housings(cities, query.nb_rooms, query.area_min, query.area_max, query.cost_min, query.cost_max) diff --git a/modules/pap/browser.py b/modules/pap/browser.py index c60c8cee..f57dff2f 100644 --- a/modules/pap/browser.py +++ b/modules/pap/browser.py @@ -42,7 +42,7 @@ class PapBrowser(BaseBrowser): fp = self.openurl(self.buildurl('http://www.pap.fr/index/ac-geo', q=pattern)) return json.load(fp) - def search_housings(self, cities, area_min, area_max, cost_min, cost_max): + def search_housings(self, cities, nb_rooms, area_min, area_max, cost_min, cost_max): data = {'geo_objets_ids': ','.join(cities), 'surface[min]': area_min or '', 'surface[max]': area_max or '', @@ -54,6 +54,11 @@ class PapBrowser(BaseBrowser): 'submit': 'rechercher', 'typesbien[]': 'appartement', } + + if nb_rooms: + data['nb_pieces[min]'] = nb_rooms + data['nb_pieces[max]'] = nb_rooms + self.location('/annonce/', urllib.urlencode(data)) assert self.is_on_page(SearchResultsPage) diff --git a/modules/seloger/backend.py b/modules/seloger/backend.py index fdda9c8e..d01b8ade 100644 --- a/modules/seloger/backend.py +++ b/modules/seloger/backend.py @@ -42,7 +42,7 @@ class SeLogerBackend(BaseBackend, ICapHousing): return list([]) with self.browser: - return self.browser.search_housings(cities, + return self.browser.search_housings(cities, query.nb_rooms, query.area_min, query.area_max, query.cost_min, query.cost_max) diff --git a/modules/seloger/browser.py b/modules/seloger/browser.py index 06d7d5d0..ec16367a 100644 --- a/modules/seloger/browser.py +++ b/modules/seloger/browser.py @@ -42,7 +42,7 @@ class SeLogerBrowser(BaseBrowser): fp = self.openurl(self.buildurl('http://www.seloger.com/js,ajax,villequery_v3.htm', ville=pattern, mode=1)) return json.load(fp) - def search_housings(self, cities, area_min, area_max, cost_min, cost_max): + def search_housings(self, cities, nb_rooms, area_min, area_max, cost_min, cost_max): data = {'ci': ','.join(cities), 'idtt': 1, #location 'idtypebien': 1, #appart @@ -54,6 +54,9 @@ class SeLogerBrowser(BaseBrowser): 'tri': 'd_dt_crea', } + if nb_rooms: + data['nb_pieces'] = nb_rooms + self.location(self.buildurl('http://ws.seloger.com/search.xml', **data)) assert self.is_on_page(SearchResultsPage) diff --git a/modules/seloger/pages.py b/modules/seloger/pages.py index eb815cc8..4e061437 100644 --- a/modules/seloger/pages.py +++ b/modules/seloger/pages.py @@ -63,7 +63,7 @@ class HousingPage(BasePage): housing.title = details.find('titre').text housing.text = details.find('descriptif').text.strip() - housing.cost = int(details.find('prix').text) + housing.cost = float(details.find('prix').text) housing.currency = u'€' housing.date = parse_date(details.find('dtfraicheur').text) housing.area = float(details.find('surface').text) @@ -92,4 +92,6 @@ class HousingPage(BasePage): for detail in details.xpath('./details/detail'): housing.details[detail.find('libelle').text.strip()] = detail.find('valeur').text or 'N/A' + housing.details['Reference'] = details.find('reference').text + return housing diff --git a/weboob/applications/flatboob/flatboob.py b/weboob/applications/flatboob/flatboob.py index eede005a..47fad288 100644 --- a/weboob/applications/flatboob/flatboob.py +++ b/weboob/applications/flatboob/flatboob.py @@ -145,6 +145,7 @@ class Flatboob(ReplApplication): query.area_max = self.ask_int('Enter max area') query.cost_min = self.ask_int('Enter min cost') query.cost_max = self.ask_int('Enter max cost') + query.nb_rooms = self.ask_int('Enter number of rooms') self.change_path('/housings') for backend, housing in self.do('search_housings', query): diff --git a/weboob/applications/qflatboob/main_window.py b/weboob/applications/qflatboob/main_window.py index a307c2e5..59db6aaf 100644 --- a/weboob/applications/qflatboob/main_window.py +++ b/weboob/applications/qflatboob/main_window.py @@ -85,6 +85,10 @@ class MainWindow(QtMainWindow): query['area_max'] = querydlg.ui.areaMax.value() query['cost_min'] = querydlg.ui.costMin.value() query['cost_max'] = querydlg.ui.costMax.value() + try: + query['nb_rooms'] = int(querydlg.ui.nbRooms.itemText(querydlg.ui.nbRooms.currentIndex())) + except ValueError: + query['nb_rooms'] = 0 self.config.set('queries', name, query) self.config.save() @@ -112,6 +116,7 @@ class MainWindow(QtMainWindow): query.area_max = int(q['area_max']) or None query.cost_min = int(q['cost_min']) or None query.cost_max = int(q['cost_max']) or None + query.nb_rooms = int(q['nb_rooms']) or None self.process = QtDo(self.weboob, self.addHousing) self.process.do('search_housings', query) @@ -123,8 +128,8 @@ class MainWindow(QtMainWindow): return item = QListWidgetItem() - item.setText(u'

%s

%s — %s%s (%s)
%s' % (housing.title, housing.date.strftime('%Y-%m-%d') if housing.date else 'Unknown', - housing.cost, housing.currency, housing.backend, housing.text)) + item.setText(u'

%s

%s — %sm² — %s%s (%s)
%s' % (housing.title, housing.date.strftime('%Y-%m-%d') if housing.date else 'Unknown', + housing.area, housing.cost, housing.currency, housing.backend, housing.text)) item.setData(Qt.UserRole, housing) if housing.photos is NotLoaded: @@ -225,11 +230,13 @@ class MainWindow(QtMainWindow): def display_photo(self): if not self.housing.photos: self.ui.photoUrlLabel.setText('') + self.ui.photoLabel.setText('') return if self.displayed_photo_idx >= len(self.housing.photos): self.displayed_photo_idx = len(self.housing.photos) - 1 if self.displayed_photo_idx < 0: + self.ui.photoLabel.setText('') self.ui.photoUrlLabel.setText('') return diff --git a/weboob/applications/qflatboob/ui/query.ui b/weboob/applications/qflatboob/ui/query.ui index e9f68acb..1a4c8f2f 100644 --- a/weboob/applications/qflatboob/ui/query.ui +++ b/weboob/applications/qflatboob/ui/query.ui @@ -59,6 +59,51 @@ + + + + + + Number of rooms + + + + + + + + N/A + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + + diff --git a/weboob/capabilities/housing.py b/weboob/capabilities/housing.py index 0e7ae5be..d975e3b1 100644 --- a/weboob/capabilities/housing.py +++ b/weboob/capabilities/housing.py @@ -64,6 +64,7 @@ class Query(CapBaseObject): self.add_field('area_max', int) self.add_field('cost_min', int) self.add_field('cost_max', int) + self.add_field('nb_rooms', int) class City(CapBaseObject): def __init__(self, id):