store last message datetime for each slut
This commit is contained in:
parent
0de0f2a768
commit
baa2a7de51
2 changed files with 69 additions and 77 deletions
|
|
@ -1,26 +1,24 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
# Copyright(C) 2010 Romain Bignon
|
||||||
Copyright(C) 2010 Romain Bignon
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
This program is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
||||||
it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation, version 3 of the License.
|
||||||
the Free Software Foundation, version 3 of the License.
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
||||||
GNU General Public License for more details.
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
You should have received a copy of the GNU General Public License
|
# along with this program; if not, write to the Free Software
|
||||||
along with this program; if not, write to the Free Software
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dateutil import tz
|
||||||
|
|
||||||
from weboob.backend import BaseBackend
|
from weboob.backend import BaseBackend
|
||||||
from weboob.capabilities.chat import ICapChat
|
from weboob.capabilities.chat import ICapChat
|
||||||
|
|
@ -46,7 +44,9 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
|
||||||
CONFIG = {'username': BaseBackend.ConfigField(description='Username on website'),
|
CONFIG = {'username': BaseBackend.ConfigField(description='Username on website'),
|
||||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
||||||
}
|
}
|
||||||
STORAGE = {'profiles_walker': {'viewed': []} }
|
STORAGE = {'profiles_walker': {'viewed': []},
|
||||||
|
'sluts': {},
|
||||||
|
}
|
||||||
BROWSER = AdopteUnMec
|
BROWSER = AdopteUnMec
|
||||||
|
|
||||||
def default_browser(self):
|
def default_browser(self):
|
||||||
|
|
@ -66,54 +66,47 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
|
||||||
def _iter_messages(self, thread, only_new):
|
def _iter_messages(self, thread, only_new):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
try:
|
try:
|
||||||
if not only_new or self.browser.nb_new_mails():
|
profiles = {}
|
||||||
my_name = self.browser.get_my_name()
|
|
||||||
contacts = self.browser.get_contact_list()
|
|
||||||
contacts.reverse()
|
|
||||||
|
|
||||||
for contact in contacts:
|
contacts = self.browser.get_contact_list()
|
||||||
if only_new and not contact.is_new() or thread and int(thread) != contact.get_id():
|
for contact in contacts:
|
||||||
|
if not contact.get_id() in self.storage.get('sluts'):
|
||||||
|
slut = {'lastmsg': datetime(1970,1,1),
|
||||||
|
'msgstatus': ''}
|
||||||
|
else:
|
||||||
|
slut = self.storage.get('sluts', contact.get_id())
|
||||||
|
|
||||||
|
last_msg = slut['lastmsg'].replace(tzinfo=tz.tzutc())
|
||||||
|
new_lastmsg = last_msg
|
||||||
|
|
||||||
|
if only_new and contact.get_lastmsg_date() < last_msg and contact.get_status() == slut['msgstatus'] or \
|
||||||
|
not thread is None and int(thread) != contact.get_id():
|
||||||
|
continue
|
||||||
|
|
||||||
|
mails = self.browser.get_thread_mails(contact.get_id())
|
||||||
|
for mail in mails:
|
||||||
|
if only_new and mail.get_date() <= last_msg:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mails = self.browser.get_thread_mails(contact.get_id())
|
if not mail.profile_link in profiles:
|
||||||
profile = None
|
profiles[mail.profile_link] = self.browser.get_profile(mail.profile_link)
|
||||||
for i in xrange(len(mails)):
|
mail.signature += u'\n%s' % profiles[mail.profile_link].get_profile_text()
|
||||||
mail = mails[i]
|
|
||||||
if only_new and mail.get_from() == my_name:
|
|
||||||
break
|
|
||||||
|
|
||||||
if not profile:
|
if new_lastmsg < mail.get_date():
|
||||||
profile = self.browser.get_profile(contact.get_id())
|
new_lastmsg = mail.get_date()
|
||||||
mail.signature += u'\n%s' % profile.get_profile_text()
|
|
||||||
yield mail
|
yield mail
|
||||||
|
|
||||||
|
slut['lastmsg'] = new_lastmsg
|
||||||
|
slut['msgstatus'] = contact.get_status()
|
||||||
|
self.storage.set('sluts', contact.get_id(), slut)
|
||||||
|
self.storage.save()
|
||||||
except BrowserUnavailable:
|
except BrowserUnavailable:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def post_reply(self, thread_id, reply_id, title, message):
|
def post_reply(self, thread_id, reply_id, title, message):
|
||||||
# Enqueue current awaiting messages
|
|
||||||
for mail in self._iter_messages(thread_id, True):
|
|
||||||
yield mail
|
|
||||||
with self.browser:
|
with self.browser:
|
||||||
try:
|
self.browser.post(thread_id, message)
|
||||||
self.browser.post(thread_id, message)
|
|
||||||
except AdopteCantPostMail, e:
|
|
||||||
yield Message(thread_id,
|
|
||||||
reply_id,
|
|
||||||
'Unable to send mail to %s' % thread_id,
|
|
||||||
'AuM',
|
|
||||||
datetime.now(),
|
|
||||||
content=u'Unable to send message to %s:\n\t%s\n\n---\n%s' (thread_id, unicode(e), message),
|
|
||||||
is_html=False)
|
|
||||||
else:
|
|
||||||
# Enqueue my messages and every next messages.
|
|
||||||
mails = self.browser.get_thread_mails(thread_id)
|
|
||||||
my_name = self.browser.get_my_name()
|
|
||||||
|
|
||||||
for mail in mails:
|
|
||||||
yield mail
|
|
||||||
|
|
||||||
if mail.get_from() == my_name:
|
|
||||||
break
|
|
||||||
|
|
||||||
def get_profile(self, _id):
|
def get_profile(self, _id):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,24 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
# Copyright(C) 2008-2010 Romain Bignon
|
||||||
Copyright(C) 2008 Romain Bignon
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
This program is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
||||||
it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation, version 3 of the License.
|
||||||
the Free Software Foundation, version 3 of the License.
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
||||||
GNU General Public License for more details.
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
You should have received a copy of the GNU General Public License
|
# along with this program; if not, write to the Free Software
|
||||||
along with this program; if not, write to the Free Software
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from dateutil import tz
|
||||||
|
from logging import warning
|
||||||
|
|
||||||
from weboob.backends.aum.pages.base import PageBase
|
from weboob.backends.aum.pages.base import PageBase
|
||||||
|
|
||||||
|
|
@ -101,7 +100,7 @@ class ContactItem:
|
||||||
warning('Unable to parse lastmsg ("%s" is not a valid unit)' % m.group(2))
|
warning('Unable to parse lastmsg ("%s" is not a valid unit)' % m.group(2))
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return datetime.now() - timedelta(seconds=i)
|
return datetime.now(tz=tz.tzutc()) - timedelta(seconds=i)
|
||||||
else:
|
else:
|
||||||
warning('Unable to parse lastmsg [%s]' % s)
|
warning('Unable to parse lastmsg [%s]' % s)
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue