can looking for a rent or a sale
This commit is contained in:
parent
3eddf8e6dd
commit
f5ca33f80e
9 changed files with 79 additions and 29 deletions
|
|
@ -41,7 +41,7 @@ class PapBackend(BaseBackend, ICapHousing):
|
|||
return list()
|
||||
|
||||
with self.browser:
|
||||
return self.browser.search_housings(cities, query.nb_rooms,
|
||||
return self.browser.search_housings(query.type, cities, query.nb_rooms,
|
||||
query.area_min, query.area_max,
|
||||
query.cost_min, query.cost_max)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import urllib
|
|||
import json
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.capabilities.housing import Query
|
||||
|
||||
from .pages import SearchResultsPage, HousingPage
|
||||
|
||||
|
|
@ -42,13 +43,16 @@ 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, nb_rooms, area_min, area_max, cost_min, cost_max):
|
||||
TYPES = {Query.TYPE_RENT: 'location',
|
||||
Query.TYPE_SALE: 'vente',
|
||||
}
|
||||
def search_housings(self, type, 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 '',
|
||||
'prix[min]': cost_min or '',
|
||||
'prix[max]': cost_max or '',
|
||||
'produit': 'location',
|
||||
'produit': self.TYPES.get(type, 'location'),
|
||||
'recherche': 1,
|
||||
'nb_resultats_par_page': 40,
|
||||
'submit': 'rechercher',
|
||||
|
|
|
|||
|
|
@ -51,7 +51,11 @@ class SearchResultsPage(BasePage):
|
|||
id = a.attrib['href'].split('-')[-1]
|
||||
housing = Housing(id)
|
||||
housing.title = a.text.strip()
|
||||
housing.cost = int(div.cssselect('td.prix')[0].text.strip(u' \t\u20ac\xa0€\n\r'))
|
||||
m = re.match('(\w+) (.+) (\d+)\xa0m\xb2 (.*)', housing.title)
|
||||
if m:
|
||||
housing.area = float(m.group(3))
|
||||
|
||||
housing.cost = float(div.cssselect('td.prix')[0].text.strip(u' \t\u20ac\xa0€\n\r').replace('.', '').replace(',', '.'))
|
||||
housing.currency = u'€'
|
||||
|
||||
m = self.DATE_RE.match(div.cssselect('p.date-publication')[0].text.strip())
|
||||
|
|
@ -75,6 +79,8 @@ class SearchResultsPage(BasePage):
|
|||
else:
|
||||
housing.text = p.text.strip()
|
||||
|
||||
housing.photos = NotAvailable
|
||||
|
||||
yield housing
|
||||
|
||||
class HousingPage(BasePage):
|
||||
|
|
@ -84,12 +90,12 @@ class HousingPage(BasePage):
|
|||
|
||||
parts = div.find('h1').text.split(' - ')
|
||||
housing.title = parts[0].strip()
|
||||
housing.cost = int(parts[1].strip(u' \t\u20ac\xa0€\n\r'))
|
||||
housing.cost = float(parts[1].strip(u' \t\u20ac\xa0€\n\r').replace('.', '').replace(',', '.'))
|
||||
housing.currency = u'€'
|
||||
|
||||
m = re.match('(\w+) ([\w\s]+) (\d+)\xa0m\xb2 (.*)', housing.title)
|
||||
m = re.match('(\w+) (.+) (\d+)\xa0m\xb2 (.*)', housing.title)
|
||||
if m:
|
||||
housing.area = int(m.group(3))
|
||||
housing.area = float(m.group(3))
|
||||
|
||||
housing.date = housing.station = housing.location = housing.phone = NotAvailable
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SeLogerBackend(BaseBackend, ICapHousing):
|
|||
return list([])
|
||||
|
||||
with self.browser:
|
||||
return self.browser.search_housings(cities, query.nb_rooms,
|
||||
return self.browser.search_housings(query.type, cities, query.nb_rooms,
|
||||
query.area_min, query.area_max,
|
||||
query.cost_min, query.cost_max)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
import json
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.capabilities.housing import Query
|
||||
|
||||
from .pages import SearchResultsPage, HousingPage
|
||||
|
||||
|
|
@ -42,18 +43,27 @@ 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, nb_rooms, area_min, area_max, cost_min, cost_max):
|
||||
TYPES = {Query.TYPE_RENT: 1,
|
||||
Query.TYPE_SALE: 2
|
||||
}
|
||||
|
||||
def search_housings(self, type, cities, nb_rooms, area_min, area_max, cost_min, cost_max):
|
||||
data = {'ci': ','.join(cities),
|
||||
'idtt': 1, #location
|
||||
'idtt': self.TYPES.get(type, 1),
|
||||
'idtypebien': 1, #appart
|
||||
'org': 'advanced_search',
|
||||
'px_loyermax': cost_max or '',
|
||||
'px_loyermin': cost_min or '',
|
||||
'surfacemax': area_max or '',
|
||||
'surfacemin': area_min or '',
|
||||
'tri': 'd_dt_crea',
|
||||
}
|
||||
|
||||
if type == Query.TYPE_SALE:
|
||||
data['pxmax'] = cost_max or ''
|
||||
data['pxmin'] = cost_min or ''
|
||||
else:
|
||||
data['px_loyermax'] = cost_max or ''
|
||||
data['px_loyermin'] = cost_min or ''
|
||||
|
||||
if nb_rooms:
|
||||
data['nb_pieces'] = nb_rooms
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue