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

@ -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']

View file

@ -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