add housing photos
This commit is contained in:
parent
81bf44cec6
commit
0c522d948a
4 changed files with 41 additions and 5 deletions
|
|
@ -68,7 +68,13 @@ class SeLogerBackend(BaseBackend, ICapHousing):
|
|||
|
||||
def fill_housing(self, housing, fields):
|
||||
with self.browser:
|
||||
return self.browser.get_housing(housing.id)
|
||||
if fields != ['photos'] or not housing.photos:
|
||||
housing = self.browser.get_housing(housing.id)
|
||||
if 'photos' in fields:
|
||||
for photo in housing.photos:
|
||||
if not photo.data:
|
||||
photo.data = self.browser.readurl(photo.url)
|
||||
return housing
|
||||
|
||||
OBJECTS = {Housing: fill_housing,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
|
||||
import json
|
||||
|
||||
from weboob.capabilities.base import NotAvailable
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from .pages import SearchResultsPage, HousingPage
|
||||
from .pages import SearchResultsPage, HousingPage, HousingPhotosPage
|
||||
|
||||
|
||||
__all__ = ['SeLogerBrowser']
|
||||
|
|
@ -36,6 +37,7 @@ class SeLogerBrowser(BaseBrowser):
|
|||
'http://www.seloger.com/(pre)?recherche.htm.*': SearchResultsPage,
|
||||
'http://www.seloger.com/annonces.htm.*': SearchResultsPage,
|
||||
'http://www.seloger.com/annonces/.*': HousingPage,
|
||||
'http://www.seloger.com/\d+/incl_detail_annonce_load_diapo_new.htm': HousingPhotosPage,
|
||||
}
|
||||
|
||||
def search_geo(self, pattern):
|
||||
|
|
@ -62,4 +64,9 @@ class SeLogerBrowser(BaseBrowser):
|
|||
self.location('/%d/detail_new.htm' % int(id))
|
||||
|
||||
assert self.is_on_page(HousingPage)
|
||||
return self.page.get_housing(obj)
|
||||
housing = self.page.get_housing(obj)
|
||||
|
||||
self.location('/%d/incl_detail_annonce_load_diapo_new.htm' % int(id))
|
||||
housing.photos = list(self.page.iter_photos()) or NotAvailable
|
||||
|
||||
return housing
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ from datetime import date
|
|||
|
||||
from weboob.tools.browser import BasePage, BrokenPageError
|
||||
from weboob.capabilities.base import NotAvailable
|
||||
from weboob.capabilities.housing import Housing
|
||||
from weboob.capabilities.housing import Housing, HousingPhoto
|
||||
|
||||
|
||||
__all__ = ['SearchResultsPage', 'HousingPage']
|
||||
__all__ = ['SearchResultsPage', 'HousingPage', 'HousingPhotosPage']
|
||||
|
||||
|
||||
def sanitarize_cost(t):
|
||||
|
|
@ -98,3 +98,10 @@ class HousingPage(BasePage):
|
|||
housing.location = NotAvailable
|
||||
|
||||
return housing
|
||||
|
||||
class HousingPhotosPage(BasePage):
|
||||
def iter_photos(self):
|
||||
for i, li in enumerate(self.document.getroot().xpath('//li')):
|
||||
photo = HousingPhoto(i)
|
||||
photo.url = li.attrib['rel'].split('|')[0]
|
||||
yield photo
|
||||
|
|
|
|||
|
|
@ -26,6 +26,21 @@ from .base import IBaseCap, CapBaseObject
|
|||
__all__ = ['ICapHousing']
|
||||
|
||||
|
||||
class HousingPhoto(CapBaseObject):
|
||||
def __init__(self, id):
|
||||
CapBaseObject.__init__(self, id)
|
||||
self.add_field('url', basestring)
|
||||
self.add_field('data', str)
|
||||
|
||||
def __iscomplete__(self):
|
||||
return self.data
|
||||
|
||||
def __str__(self):
|
||||
return self.url
|
||||
|
||||
def __repr__(self):
|
||||
return u'<HousingPhoto "%s" data=%do>' % (self.id, len(self.data) if self.data else 0)
|
||||
|
||||
class Housing(CapBaseObject):
|
||||
def __init__(self, id):
|
||||
CapBaseObject.__init__(self, id)
|
||||
|
|
@ -38,6 +53,7 @@ class Housing(CapBaseObject):
|
|||
self.add_field('station', basestring)
|
||||
self.add_field('text', basestring)
|
||||
self.add_field('phone', basestring)
|
||||
self.add_field('photos', list)
|
||||
|
||||
class Query(CapBaseObject):
|
||||
def __init__(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue