improvement of profiles in contacts

This commit is contained in:
Romain Bignon 2010-07-07 16:44:56 +02:00
commit 47a5c8028e
5 changed files with 112 additions and 44 deletions

View file

@ -119,7 +119,7 @@ class IGroup(object):
class MetaGroup(IGroup): class MetaGroup(IGroup):
def iter_contacts(self, cb): def iter_contacts(self, cb):
if self.id == 'online': if self.id == 'online':
status = Contact.STATUS_ONLINE status = Contact.STATUS_ONLINE|Contact.STATUS_AWAY
elif self.id == 'offline': elif self.id == 'offline':
status = Contact.STATUS_OFFLINE status = Contact.STATUS_OFFLINE
else: else:
@ -172,11 +172,20 @@ class ContactsWidget(QWidget):
status = '' status = ''
if contact.status == Contact.STATUS_ONLINE: if contact.status == Contact.STATUS_ONLINE:
status = 'Online' status = u'Online'
status_color = 0x00aa00 status_color = 0x00aa00
elif contact.status == Contact.STATUS_OFFLINE: elif contact.status == Contact.STATUS_OFFLINE:
status = 'Offline' status = u'Offline'
status_color = 0xff0000 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 = QListWidgetItem()
item.setText('<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, contact.backend.name)) item.setText('<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, contact.backend.name))

View file

@ -163,10 +163,34 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
else: else:
return return
def get_profile(self, _id): def get_contact(self, _id):
try: try:
with self.browser: 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: except BrowserUnavailable:
return None 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_PROFILE_WALKER = ProfilesWalker(self.weboob.scheduler, self.storage, self.browser)
self.OPTIM_VISIBILITY = Visibility(self.weboob.scheduler, 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: with self.browser:
for contact in self.browser.iter_contacts(): for contact in self.browser.iter_contacts():
s = 0
if contact['cat'] == 1: if contact['cat'] == 1:
s = Contact.STATUS_ONLINE s = Contact.STATUS_ONLINE
elif contact['cat'] == 3: elif contact['cat'] == 3:
s = Contact.STATUS_OFFLINE s = Contact.STATUS_OFFLINE
elif contact['cat'] == 2:
s = Contact.STATUS_AWAY
else: else:
warning('Unknown AuM contact status: %s' % contact['cat']) warning('Unknown AuM contact status: %s' % contact['cat'])
if not status & s: if not status & s or ids and contact['id'] in ids:
continue continue
# TODO age in contact['birthday'] # TODO age in contact['birthday']

View file

@ -17,7 +17,6 @@
from weboob.backends.aum.pages.base import PageBase from weboob.backends.aum.pages.base import PageBase
from weboob.capabilities.dating import Profile
from copy import deepcopy from copy import deepcopy
from logging import warning from logging import warning
@ -124,7 +123,7 @@ class FieldParticularSignes(FieldBase):
elif s.find('rousseur') >= 0: elif s.find('rousseur') >= 0:
d['freckle'] = True d['freckle'] = True
class ProfilePage(PageBase, Profile): class ProfilePage(PageBase):
empty_table = {'details': {'old': 0, empty_table = {'details': {'old': 0,
'birthday': (0,0,0), 'birthday': (0,0,0),
'zipcode': 0, 'zipcode': 0,
@ -397,3 +396,27 @@ class ProfilePage(PageBase, Profile):
def get_stats(self): def get_stats(self):
return self.stats 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

View file

@ -21,6 +21,15 @@ from .cap import ICap
__all__ = ['ICapContact', 'Contact'] __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): class Contact(object):
STATUS_ONLINE = 0x001 STATUS_ONLINE = 0x001
@ -28,24 +37,52 @@ class Contact(object):
STATUS_AWAY = 0x004 STATUS_AWAY = 0x004
STATUS_ALL = 0xfff 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.id = id
self.name = name self.name = name
self.status = status self.status = status
self.photo_url = photo_url self.status_msg = u''
self.thumbnail_url = thumbnail_url self.summary = u''
self.avatar = None
self.photos = []
self.profile = None
def iter_fields(self): def iter_fields(self):
return {'id': self.id, return {'id': self.id,
'name': self.name, 'name': self.name,
'status': self.status, 'status': self.status,
'photo_url': self.photo_url, 'status_msg': self.status_msg,
'thumbnail_url': self.thumbnail_url, 'summary': self.summary,
'avatar': self.avatar,
'photos': self.photos,
'profile': self.profile,
}.iteritems() }.iteritems()
class ICapContact(ICap): 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() raise NotImplementedError()
def get_contact(self, id): 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

View file

@ -22,31 +22,6 @@ from .cap import ICap
__all__ = ['ICapDating', 'Profile'] __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 OptimizationNotFound(Exception): pass
class Optimization(object): class Optimization(object):
@ -67,9 +42,6 @@ class StatusField(object):
self.flags = flags self.flags = flags
class ICapDating(ICap): class ICapDating(ICap):
def get_profile(self, _id):
raise NotImplementedError()
def get_status(self): def get_status(self):
""" """
Get a list of fields Get a list of fields