move code to create Contact in backend.py
This commit is contained in:
parent
e104e36153
commit
8fd3468352
2 changed files with 19 additions and 14 deletions
|
|
@ -20,6 +20,7 @@ from __future__ import with_statement
|
|||
from datetime import datetime
|
||||
from dateutil import tz
|
||||
import os
|
||||
from logging import warning
|
||||
from time import sleep
|
||||
|
||||
from weboob.backend import BaseBackend
|
||||
|
|
@ -175,7 +176,22 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
|
|||
|
||||
def iter_contacts(self, status=Contact.STATUS_ALL):
|
||||
with self.browser:
|
||||
return self.browser.iter_contacts(status)
|
||||
for contact in self.browser.iter_contacts():
|
||||
if contact['cat'] == 1:
|
||||
s = Contact.STATUS_ONLINE
|
||||
elif contact['cat'] == 3:
|
||||
s = Contact.STATUS_OFFLINE
|
||||
else:
|
||||
warning('Unknown AuM contact status: %s' % contact['cat'])
|
||||
|
||||
if not status & s:
|
||||
continue
|
||||
|
||||
# TODO age in contact['birthday']
|
||||
contact = Contact(contact['id'], contact['pseudo'], s)
|
||||
contact.status_msg = u'%s old' % contact['birthday']
|
||||
contact.thumbnail_url = contact['cover']
|
||||
yield contact
|
||||
|
||||
def iter_chat_messages(self, _id=None):
|
||||
with self.browser:
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ from weboob.backends.aum.pages.edit import EditPhotoPage, EditPhotoCbPage, EditA
|
|||
from weboob.backends.aum.pages.wait import WaitPage
|
||||
|
||||
from weboob.capabilities.chat import ChatException, ChatMessage
|
||||
from weboob.capabilities.contact import Contact
|
||||
|
||||
|
||||
__all__ = ['AdopteUnMec']
|
||||
|
|
@ -286,7 +285,7 @@ class AdopteUnMec(BaseBrowser):
|
|||
raise ChatException(u'Error while getting chat infos. json:\n%s' % json)
|
||||
return json
|
||||
|
||||
def iter_contacts(self, status=Contact.STATUS_ALL):
|
||||
def iter_contacts(self):
|
||||
def iter_dedupe(contacts):
|
||||
yielded_ids = set()
|
||||
for contact in contacts:
|
||||
|
|
@ -295,17 +294,7 @@ class AdopteUnMec(BaseBrowser):
|
|||
yielded_ids.add(contact['id'])
|
||||
|
||||
json = self._get_chat_infos()
|
||||
for contact in iter_dedupe(json['contacts']):
|
||||
if status & Contact.STATUS_ONLINE and contact['cat'] == 1 or \
|
||||
status & Contact.STATUS_OFFLINE and contact['cat'] == 3:
|
||||
if contact['cat'] == 1:
|
||||
s = Contact.STATUS_ONLINE
|
||||
elif contact['cat'] == 3:
|
||||
s = Contact.STATUS_OFFLINE
|
||||
else:
|
||||
raise ChatException(u'Unknown online status: contact=%s' % contact)
|
||||
# TODO age in contact['birthday']
|
||||
yield Contact(id=contact['id'], name=contact['pseudo'], status=s, thumbnail_url=contact['cover'])
|
||||
return iter_dedupe(json['contacts'])
|
||||
|
||||
def iter_chat_messages(self, _id=None):
|
||||
json = self._get_chat_infos()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue