[okc] Photos handling in profile

This commit is contained in:
Roger Philibert 2012-03-21 21:37:12 +01:00 committed by Romain Bignon
commit cba809a8d0
3 changed files with 26 additions and 12 deletions

View file

@ -242,13 +242,13 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact):
data = self.browser.openurl(photo.thumbnail_url).read()
contact.set_photo(name, thumbnail_data=data)
#def fill_photo(self, photo, fields):
# with self.browser:
# if 'data' in fields and photo.url and not photo.data:
# photo.data = self.browser.readurl(photo.url)
# if 'thumbnail_data' in fields and photo.thumbnail_url and not photo.thumbnail_data:
# photo.thumbnail_data = self.browser.readurl(photo.thumbnail_url)
# return photo
def fill_photo(self, photo, fields):
with self.browser:
if 'data' in fields and photo.url and not photo.data:
photo.data = self.browser.readurl(photo.url)
if 'thumbnail_data' in fields and photo.thumbnail_url and not photo.thumbnail_data:
photo.thumbnail_data = self.browser.readurl(photo.thumbnail_url)
return photo
def get_contact(self, contact):
with self.browser:
@ -280,6 +280,8 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact):
contact.status = Contact.STATUS_OFFLINE
contact.status_msg = contact.profile['details']['last_online'].value
for no, photo in enumerate(self.browser.get_photos(_id)):
contact.set_photo('image_%i' % no, url=photo, thumbnail_url=photo)
return contact
#def _get_partial_contact(self, contact):
@ -355,5 +357,5 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact):
OBJECTS = {Thread: fill_thread,
Contact: fill_contact,
#ContactPhoto: fill_photo
ContactPhoto: fill_photo
}

View file

@ -32,7 +32,7 @@ except ImportError:
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserUnavailable
from weboob.tools.ordereddict import OrderedDict
from .pages import LoginPage, ThreadPage, MessagesPage, ProfilePage
from .pages import LoginPage, ThreadPage, MessagesPage, ProfilePage, PhotosPage
__all__ = ['OkCBrowser']
@ -48,7 +48,8 @@ class OkCBrowser(BaseBrowser):
('https://%s/login.*' % DOMAIN, LoginPage),
('http://%s/messages' % DOMAIN, ThreadPage),
('http://%s/messages\?.*' % DOMAIN, MessagesPage),
('http://%s/profile/.*' % DOMAIN, ProfilePage),
('http://%s/profile/.*/photos' % DOMAIN, PhotosPage),
('http://%s/profile/[^/]*' % DOMAIN, ProfilePage),
))
@ -200,9 +201,15 @@ class OkCBrowser(BaseBrowser):
# return set(ids)
@check_login
def get_profile(self, id, with_pics=True):
def get_profile(self, id):
self.location(self.absurl('/profile/%s' % id))
return self.page.get_profile()
profile = self.page.get_profile()
return profile
@check_login
def get_photos(self, id):
self.location(self.absurl('/profile/%s/photos' % id))
return self.page.get_photos()
#def _get_chat_infos(self):
# try:

View file

@ -129,3 +129,8 @@ class ProfilePage(BasePage):
profile['data']['details'].value[key] = ProfileNode(key, label, val)
return profile
class PhotosPage(BasePage):
def get_photos(self):
imgs = self.parser.select(self.document.getroot(), "//div[@class='pic clearfix']//img", method='xpath')
return [img.get('src') for img in imgs]