adapt to new ICapMessages API

This commit is contained in:
Romain Bignon 2010-08-30 16:38:34 +02:00
commit e7c24c13c8
12 changed files with 381 additions and 249 deletions

View file

@ -16,6 +16,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
import time
from datetime import datetime
from dateutil import tz
from logging import error, warning
@ -23,9 +24,8 @@ from mechanize import FormNotFoundError
from weboob.backends.aum.pages.base import PageBase
from weboob.backends.aum.exceptions import AdopteCantPostMail
from weboob.capabilities.messages import Message
class MailParser(Message):
class MailParser(object):
"""
<td>
@ -93,8 +93,14 @@ class MailParser(Message):
def __init__(self, thread_id, name, tr):
# <td> <table> implicit<tbody> <tr>
Message.__init__(self, thread_id, 0, 'Discussion with %s' % name, name)
self.thread_id = thread_id
self.date = None
self.message_id = 0
self.title = 'Discussion with %s' % name
self.sender = name
self.name = name
self.tr = tr.childNodes[0].childNodes[1].childNodes[0].childNodes[0]
self.new = False
tds = self.tr.childNodes
@ -131,6 +137,10 @@ class MailParser(Message):
self.parse_profile_link()
self.parse_from()
@property
def date_int(self):
return int(time.strftime('%Y%m%d%H%M%S', self.date.timetuple()))
def set_parent_message_id(self, date):
self.parent_message_id = date
@ -157,7 +167,7 @@ class MailParser(Message):
self.id = '%s.%s' % (self.thread_id, self.message_id)
if m.group(7).find('nouveau') >= 0:
self.flags |= self.IS_UNREAD
self.new = True
else:
error('Error: unable to parse the datetime string "%s"' % date_str)

View file

@ -16,6 +16,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
from weboob.tools.browser import BrowserIncorrectPassword
from .base import PageBase
@ -29,7 +31,29 @@ class LoginPage(PageBase):
self.browser.submit() # submit current form
class RegisterError(Exception):
pass
class RegisterPage(PageBase):
def on_loaded(self):
display_errors = False
for div in self.document.getElementsByTagName('div'):
if div.getAttribute('class') == 'balloon':
display_errors = True
break
if not display_errors:
return
errors = []
for script in self.document.getElementsByTagName('script'):
for child in script.childNodes:
if child and child.data.find('dispErrors') >= 0:
for m in re.finditer('"(\w+)": "(.*)",', child.data):
errors.append(m.group(2))
raise RegisterError(u'Unable to register account: %s' % ', '.join(errors))
def register(self, password, sex, birthday_d, birthday_m, birthday_y, zipcode, country):
"""
Form name=register (#1)
@ -53,7 +77,7 @@ Form name=register (#1)
self.browser.select_form(name='register')
self.browser.set_all_readonly(False)
self.browser['sex'] = str(sex)
self.browser['sex'] = [str(sex)]
self.browser['birthday0'] = [str(birthday_d)]
self.browser['birthday1'] = [str(birthday_m)]
self.browser['birthday2'] = [str(birthday_y)]