From 47a5c8028e9b31a4d4b93dccd1b9967c4ba5d1b5 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Wed, 7 Jul 2010 16:44:56 +0200 Subject: [PATCH] improvement of profiles in contacts --- weboob/applications/qhavesex/contacts.py | 15 +++++-- weboob/backends/aum/backend.py | 35 ++++++++++++++-- weboob/backends/aum/pages/profile.py | 27 ++++++++++++- weboob/capabilities/contact.py | 51 ++++++++++++++++++++---- weboob/capabilities/dating.py | 28 ------------- 5 files changed, 112 insertions(+), 44 deletions(-) diff --git a/weboob/applications/qhavesex/contacts.py b/weboob/applications/qhavesex/contacts.py index b6931cd9..5b51034a 100644 --- a/weboob/applications/qhavesex/contacts.py +++ b/weboob/applications/qhavesex/contacts.py @@ -119,7 +119,7 @@ class IGroup(object): class MetaGroup(IGroup): def iter_contacts(self, cb): if self.id == 'online': - status = Contact.STATUS_ONLINE + status = Contact.STATUS_ONLINE|Contact.STATUS_AWAY elif self.id == 'offline': status = Contact.STATUS_OFFLINE else: @@ -172,11 +172,20 @@ class ContactsWidget(QWidget): status = '' if contact.status == Contact.STATUS_ONLINE: - status = 'Online' + status = u'Online' status_color = 0x00aa00 elif contact.status == Contact.STATUS_OFFLINE: - status = 'Offline' + status = u'Offline' status_color = 0xff0000 + elif contact.status == Contact.STATUS_AWAY: + status = u'Away' + status_color = 0xffad16 + else: + status = u'Unknown' + status_color = 0xaaaaaa + + if contact.status_msg: + status += u' — %s' % contact.status_msg item = QListWidgetItem() item.setText('

%s

%s
%s' % (contact.name, status_color, status, contact.backend.name)) diff --git a/weboob/backends/aum/backend.py b/weboob/backends/aum/backend.py index 8310685e..b0af5ac2 100644 --- a/weboob/backends/aum/backend.py +++ b/weboob/backends/aum/backend.py @@ -163,10 +163,34 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC else: return - def get_profile(self, _id): + def get_contact(self, _id): try: with self.browser: - return self.browser.get_profile(_id) + profile = self.browser.get_profide(_id) + + if profile.is_online(): + s = Contact.STATUS_ONLINE + else: + s = Contact.STATUS_OFFLINE + contact = Contact(_id, profile.get_name(), s) + contact.status_msg = u'%s old' % profile.table['details']['old'] + contact.summary = profile.description + contact.avatar = None + contact.photos = profile.photos + #body += u'\nStats:' + #for label, value in self.get_stats().iteritems(): + # body += u'\n\t\t%-15s %s' % (label + ':', value) + #body += u'\n\nInformations:' + #for section, d in self.get_table().iteritems(): + # body += u'\n\t%s\n' % section + # for key, value in d.items(): + # key = '%s:' % key + # if isinstance(value, list): + # body += u'\t\t%-15s %s\n' % (key, u', '.join([unicode(s) for s in value])) + # elif isinstance(value, float): + # body += u'\t\t%-15s %.2f\n' % (key, value) + # else: + # body += u'\t\t%-15s %s\n' % (key, unicode(value)) except BrowserUnavailable: return None @@ -174,17 +198,20 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC self.OPTIM_PROFILE_WALKER = ProfilesWalker(self.weboob.scheduler, self.storage, self.browser) self.OPTIM_VISIBILITY = Visibility(self.weboob.scheduler, self.browser) - def iter_contacts(self, status=Contact.STATUS_ALL): + def iter_contacts(self, status=Contact.STATUS_ALL, ids=None): with self.browser: for contact in self.browser.iter_contacts(): + s = 0 if contact['cat'] == 1: s = Contact.STATUS_ONLINE elif contact['cat'] == 3: s = Contact.STATUS_OFFLINE + elif contact['cat'] == 2: + s = Contact.STATUS_AWAY else: warning('Unknown AuM contact status: %s' % contact['cat']) - if not status & s: + if not status & s or ids and contact['id'] in ids: continue # TODO age in contact['birthday'] diff --git a/weboob/backends/aum/pages/profile.py b/weboob/backends/aum/pages/profile.py index 94dcb1e5..12d0cd3e 100644 --- a/weboob/backends/aum/pages/profile.py +++ b/weboob/backends/aum/pages/profile.py @@ -17,7 +17,6 @@ from weboob.backends.aum.pages.base import PageBase -from weboob.capabilities.dating import Profile from copy import deepcopy from logging import warning @@ -124,7 +123,7 @@ class FieldParticularSignes(FieldBase): elif s.find('rousseur') >= 0: d['freckle'] = True -class ProfilePage(PageBase, Profile): +class ProfilePage(PageBase): empty_table = {'details': {'old': 0, 'birthday': (0,0,0), 'zipcode': 0, @@ -397,3 +396,27 @@ class ProfilePage(PageBase, Profile): def get_stats(self): return self.stats + + def get_profile_text(self): + body = u'Status: %s' % unicode(self.status) + if self.photos: + body += u'\nPhotos:' + for photo in self.photos: + body += u'\n\t\t%s' % unicode(photo) + body += u'\nStats:' + for label, value in self.get_stats().iteritems(): + body += u'\n\t\t%-15s %s' % (label + ':', value) + body += u'\n\nInformations:' + for section, d in self.get_table().iteritems(): + body += u'\n\t%s\n' % section + for key, value in d.items(): + key = '%s:' % key + if isinstance(value, list): + body += u'\t\t%-15s %s\n' % (key, u', '.join([unicode(s) for s in value])) + elif isinstance(value, float): + body += u'\t\t%-15s %.2f\n' % (key, value) + else: + body += u'\t\t%-15s %s\n' % (key, unicode(value)) + body += u'\n\nDescription:\n%s' % unicode(self.get_description()) + + return body diff --git a/weboob/capabilities/contact.py b/weboob/capabilities/contact.py index cca46eca..1aa491bf 100644 --- a/weboob/capabilities/contact.py +++ b/weboob/capabilities/contact.py @@ -21,6 +21,15 @@ from .cap import ICap __all__ = ['ICapContact', 'Contact'] +class ProfileNode(object): + HEAD = 0x01 + + def __init__(self, name, label, value, sufix=None, flags=None): + self.name = name + self.label = label + self.value = value + self.sufix = sufix + self.flags = flags class Contact(object): STATUS_ONLINE = 0x001 @@ -28,24 +37,52 @@ class Contact(object): STATUS_AWAY = 0x004 STATUS_ALL = 0xfff - def __init__(self, id, name, status, photo_url=None, thumbnail_url=None): + def __init__(self, id, name, status): self.id = id self.name = name self.status = status - self.photo_url = photo_url - self.thumbnail_url = thumbnail_url + self.status_msg = u'' + self.summary = u'' + self.avatar = None + self.photos = [] + self.profile = None def iter_fields(self): return {'id': self.id, 'name': self.name, 'status': self.status, - 'photo_url': self.photo_url, - 'thumbnail_url': self.thumbnail_url, + 'status_msg': self.status_msg, + 'summary': self.summary, + 'avatar': self.avatar, + 'photos': self.photos, + 'profile': self.profile, }.iteritems() class ICapContact(ICap): - def iter_contacts(self, status=Contact.STATUS_ALL): + def iter_contacts(self, status=Contact.STATUS_ALL, ids=None): + """ + Iter contacts + + @param status get only contacts with the specified status + @param ids if set, get the specified contacts + @return iterator over the contacts found + """ raise NotImplementedError() def get_contact(self, id): - raise NotImplementedError() + """ + Get a contact from his id. + + The default implementation only calls iter_contacts() + with the proper values, but it might be overloaded + by backends. + + @param id the ID requested + @return the Contact object, or None if not found + """ + + l = self.iter_contacts(ids=[id]) + try: + return l[0] + except IndexError: + return None diff --git a/weboob/capabilities/dating.py b/weboob/capabilities/dating.py index c8bc7f50..256963cf 100644 --- a/weboob/capabilities/dating.py +++ b/weboob/capabilities/dating.py @@ -22,31 +22,6 @@ from .cap import ICap __all__ = ['ICapDating', 'Profile'] -class Profile(object): - def get_profile_text(self): - body = u'Status: %s' % unicode(self.status) - if self.photos: - body += u'\nPhotos:' - for photo in self.photos: - body += u'\n\t\t%s' % unicode(photo) - body += u'\nStats:' - for label, value in self.get_stats().iteritems(): - body += u'\n\t\t%-15s %s' % (label + ':', value) - body += u'\n\nInformations:' - for section, d in self.get_table().iteritems(): - body += u'\n\t%s\n' % section - for key, value in d.items(): - key = '%s:' % key - if isinstance(value, list): - body += u'\t\t%-15s %s\n' % (key, u', '.join([unicode(s) for s in value])) - elif isinstance(value, float): - body += u'\t\t%-15s %.2f\n' % (key, value) - else: - body += u'\t\t%-15s %s\n' % (key, unicode(value)) - body += u'\n\nDescription:\n%s' % unicode(self.get_description()) - - return body - class OptimizationNotFound(Exception): pass class Optimization(object): @@ -67,9 +42,6 @@ class StatusField(object): self.flags = flags class ICapDating(ICap): - def get_profile(self, _id): - raise NotImplementedError() - def get_status(self): """ Get a list of fields