From fc9f6b439f4899f8bfc3ff5f99f00ee921849888 Mon Sep 17 00:00:00 2001 From: Christophe Benz Date: Fri, 19 Nov 2010 04:38:19 +0100 Subject: [PATCH] store if photo is hidden --- weboob/backends/aum/backend.py | 5 +++-- weboob/backends/aum/pages/profile.py | 10 +++++++++- weboob/capabilities/contact.py | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/weboob/backends/aum/backend.py b/weboob/backends/aum/backend.py index a2b7179b..468fe6df 100644 --- a/weboob/backends/aum/backend.py +++ b/weboob/backends/aum/backend.py @@ -301,7 +301,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh if photo.url: data = self.browser.openurl(photo.url).read() contact.set_photo(name, data=data) - if photo.thumbnail_url: + elif photo.thumbnail_url: data = self.browser.openurl(photo.thumbnail_url).read() contact.set_photo(name, thumbnail_data=data) @@ -335,7 +335,8 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh contact.status_msg = profile.get_status() contact.summary = profile.description for photo in profile.photos: - contact.set_photo(photo.split('/')[-1], url=photo, thumbnail_url=photo.replace('image', 'thumb1_')) + contact.set_photo(photo['url'].split('/')[-1], url=photo['url'], + thumbnail_url=photo['url'].replace('image', 'thumb1_'), shown=photo['shown']) contact.profile = [] stats = ProfileNode('stats', 'Stats', [], flags=ProfileNode.HEAD|ProfileNode.SECTION) diff --git a/weboob/backends/aum/pages/profile.py b/weboob/backends/aum/pages/profile.py index 4ca1a03c..6f740fd4 100644 --- a/weboob/backends/aum/pages/profile.py +++ b/weboob/backends/aum/pages/profile.py @@ -265,7 +265,15 @@ class ProfilePage(PageBase): if div.hasAttribute('background'): m = self.PHOTO_REGEXP.match(div.getAttribute('background')) if m: - self.photos += [re.sub(u'thumb[0-2]_', u'image', div.getAttribute('background'))] + self.photos.append(dict(url=re.sub(u'thumb[0-2]_', u'image', div.getAttribute('background')), + shown=True)) + photo_regex = re.compile('(?Phttp://.+\.adopteunmec\.com/.+/)image(?P.+)\.jpg') + photo_max_id = max(int(photo_regex.match(photo['url']).groupdict()['id']) for photo in self.photos) + base_url = photo_regex.match(self.photos[0]['url']).groupdict()['base_url'] + for id in xrange(1, photo_max_id + 1): + url = '%simage%s.jpg' % (base_url, id) + if not url in [photo['url'] for photo in self.photos]: + self.photos.append(dict(url=url, shown=False)) if div.hasAttribute('width') and str(div.getAttribute('width')) == '226': trs = div.getElementsByTagName('tr') for tr in trs: diff --git a/weboob/capabilities/contact.py b/weboob/capabilities/contact.py index 65eb45e6..97db4b25 100644 --- a/weboob/capabilities/contact.py +++ b/weboob/capabilities/contact.py @@ -41,6 +41,7 @@ class ContactPhoto(CapBaseObject): self.add_field('data', str) self.add_field('thumbnail_url', basestring) self.add_field('thumbnail_data', basestring) + self.add_field('shown', bool) def __iscomplete__(self): return (self.data and (not self.thumbnail_url or self.thumbnail_data))