add parameter 'nb_rooms' in queries
This commit is contained in:
parent
825dc0b5b1
commit
b6379f7f37
9 changed files with 71 additions and 7 deletions
|
|
@ -41,7 +41,7 @@ class PapBackend(BaseBackend, ICapHousing):
|
||||||
return list()
|
return list()
|
||||||
|
|
||||||
with self.browser:
|
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.area_min, query.area_max,
|
||||||
query.cost_min, query.cost_max)
|
query.cost_min, query.cost_max)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class PapBrowser(BaseBrowser):
|
||||||
fp = self.openurl(self.buildurl('http://www.pap.fr/index/ac-geo', q=pattern))
|
fp = self.openurl(self.buildurl('http://www.pap.fr/index/ac-geo', q=pattern))
|
||||||
return json.load(fp)
|
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),
|
data = {'geo_objets_ids': ','.join(cities),
|
||||||
'surface[min]': area_min or '',
|
'surface[min]': area_min or '',
|
||||||
'surface[max]': area_max or '',
|
'surface[max]': area_max or '',
|
||||||
|
|
@ -54,6 +54,11 @@ class PapBrowser(BaseBrowser):
|
||||||
'submit': 'rechercher',
|
'submit': 'rechercher',
|
||||||
'typesbien[]': 'appartement',
|
'typesbien[]': 'appartement',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nb_rooms:
|
||||||
|
data['nb_pieces[min]'] = nb_rooms
|
||||||
|
data['nb_pieces[max]'] = nb_rooms
|
||||||
|
|
||||||
self.location('/annonce/', urllib.urlencode(data))
|
self.location('/annonce/', urllib.urlencode(data))
|
||||||
assert self.is_on_page(SearchResultsPage)
|
assert self.is_on_page(SearchResultsPage)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class SeLogerBackend(BaseBackend, ICapHousing):
|
||||||
return list([])
|
return list([])
|
||||||
|
|
||||||
with self.browser:
|
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.area_min, query.area_max,
|
||||||
query.cost_min, query.cost_max)
|
query.cost_min, query.cost_max)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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))
|
fp = self.openurl(self.buildurl('http://www.seloger.com/js,ajax,villequery_v3.htm', ville=pattern, mode=1))
|
||||||
return json.load(fp)
|
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),
|
data = {'ci': ','.join(cities),
|
||||||
'idtt': 1, #location
|
'idtt': 1, #location
|
||||||
'idtypebien': 1, #appart
|
'idtypebien': 1, #appart
|
||||||
|
|
@ -54,6 +54,9 @@ class SeLogerBrowser(BaseBrowser):
|
||||||
'tri': 'd_dt_crea',
|
'tri': 'd_dt_crea',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nb_rooms:
|
||||||
|
data['nb_pieces'] = nb_rooms
|
||||||
|
|
||||||
self.location(self.buildurl('http://ws.seloger.com/search.xml', **data))
|
self.location(self.buildurl('http://ws.seloger.com/search.xml', **data))
|
||||||
|
|
||||||
assert self.is_on_page(SearchResultsPage)
|
assert self.is_on_page(SearchResultsPage)
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class HousingPage(BasePage):
|
||||||
|
|
||||||
housing.title = details.find('titre').text
|
housing.title = details.find('titre').text
|
||||||
housing.text = details.find('descriptif').text.strip()
|
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.currency = u'€'
|
||||||
housing.date = parse_date(details.find('dtfraicheur').text)
|
housing.date = parse_date(details.find('dtfraicheur').text)
|
||||||
housing.area = float(details.find('surface').text)
|
housing.area = float(details.find('surface').text)
|
||||||
|
|
@ -92,4 +92,6 @@ class HousingPage(BasePage):
|
||||||
for detail in details.xpath('./details/detail'):
|
for detail in details.xpath('./details/detail'):
|
||||||
housing.details[detail.find('libelle').text.strip()] = detail.find('valeur').text or 'N/A'
|
housing.details[detail.find('libelle').text.strip()] = detail.find('valeur').text or 'N/A'
|
||||||
|
|
||||||
|
housing.details['Reference'] = details.find('reference').text
|
||||||
|
|
||||||
return housing
|
return housing
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,7 @@ class Flatboob(ReplApplication):
|
||||||
query.area_max = self.ask_int('Enter max area')
|
query.area_max = self.ask_int('Enter max area')
|
||||||
query.cost_min = self.ask_int('Enter min cost')
|
query.cost_min = self.ask_int('Enter min cost')
|
||||||
query.cost_max = self.ask_int('Enter max cost')
|
query.cost_max = self.ask_int('Enter max cost')
|
||||||
|
query.nb_rooms = self.ask_int('Enter number of rooms')
|
||||||
|
|
||||||
self.change_path('/housings')
|
self.change_path('/housings')
|
||||||
for backend, housing in self.do('search_housings', query):
|
for backend, housing in self.do('search_housings', query):
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,10 @@ class MainWindow(QtMainWindow):
|
||||||
query['area_max'] = querydlg.ui.areaMax.value()
|
query['area_max'] = querydlg.ui.areaMax.value()
|
||||||
query['cost_min'] = querydlg.ui.costMin.value()
|
query['cost_min'] = querydlg.ui.costMin.value()
|
||||||
query['cost_max'] = querydlg.ui.costMax.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.set('queries', name, query)
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
||||||
|
|
@ -112,6 +116,7 @@ class MainWindow(QtMainWindow):
|
||||||
query.area_max = int(q['area_max']) or None
|
query.area_max = int(q['area_max']) or None
|
||||||
query.cost_min = int(q['cost_min']) or None
|
query.cost_min = int(q['cost_min']) or None
|
||||||
query.cost_max = int(q['cost_max']) 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 = QtDo(self.weboob, self.addHousing)
|
||||||
self.process.do('search_housings', query)
|
self.process.do('search_housings', query)
|
||||||
|
|
@ -123,8 +128,8 @@ class MainWindow(QtMainWindow):
|
||||||
return
|
return
|
||||||
|
|
||||||
item = QListWidgetItem()
|
item = QListWidgetItem()
|
||||||
item.setText(u'<h2>%s</h2><i>%s — %s%s (%s)</i><br />%s' % (housing.title, housing.date.strftime('%Y-%m-%d') if housing.date else 'Unknown',
|
item.setText(u'<h2>%s</h2><i>%s — %sm² — %s%s (%s)</i><br />%s' % (housing.title, housing.date.strftime('%Y-%m-%d') if housing.date else 'Unknown',
|
||||||
housing.cost, housing.currency, housing.backend, housing.text))
|
housing.area, housing.cost, housing.currency, housing.backend, housing.text))
|
||||||
item.setData(Qt.UserRole, housing)
|
item.setData(Qt.UserRole, housing)
|
||||||
|
|
||||||
if housing.photos is NotLoaded:
|
if housing.photos is NotLoaded:
|
||||||
|
|
@ -225,11 +230,13 @@ class MainWindow(QtMainWindow):
|
||||||
def display_photo(self):
|
def display_photo(self):
|
||||||
if not self.housing.photos:
|
if not self.housing.photos:
|
||||||
self.ui.photoUrlLabel.setText('')
|
self.ui.photoUrlLabel.setText('')
|
||||||
|
self.ui.photoLabel.setText('')
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.displayed_photo_idx >= len(self.housing.photos):
|
if self.displayed_photo_idx >= len(self.housing.photos):
|
||||||
self.displayed_photo_idx = len(self.housing.photos) - 1
|
self.displayed_photo_idx = len(self.housing.photos) - 1
|
||||||
if self.displayed_photo_idx < 0:
|
if self.displayed_photo_idx < 0:
|
||||||
|
self.ui.photoLabel.setText('')
|
||||||
self.ui.photoUrlLabel.setText('')
|
self.ui.photoUrlLabel.setText('')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,51 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout_3">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_10">
|
||||||
|
<property name="text">
|
||||||
|
<string>Number of rooms</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="nbRooms">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>N/A</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>1</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>2</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>3</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>4</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>5</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ class Query(CapBaseObject):
|
||||||
self.add_field('area_max', int)
|
self.add_field('area_max', int)
|
||||||
self.add_field('cost_min', int)
|
self.add_field('cost_min', int)
|
||||||
self.add_field('cost_max', int)
|
self.add_field('cost_max', int)
|
||||||
|
self.add_field('nb_rooms', int)
|
||||||
|
|
||||||
class City(CapBaseObject):
|
class City(CapBaseObject):
|
||||||
def __init__(self, id):
|
def __init__(self, id):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue