new command 'weboob-config confirm'

This commit is contained in:
Romain Bignon 2010-11-11 13:08:05 +01:00
commit 01acc2c7d4
3 changed files with 63 additions and 1 deletions

View file

@ -17,9 +17,11 @@
import os
import sys
import subprocess
import re
from weboob.capabilities.account import ICapAccount
from weboob.tools.application.repl import ReplApplication
from weboob.tools.ordereddict import OrderedDict
@ -70,6 +72,35 @@ class WeboobCfg(ReplApplication):
"""
self.register_backend(line)
def do_confirm(self, backend_name):
"""
confirm BACKEND
For a backend which support CapAccount, parse a confirmation mail
after using the 'register' command to automatically confirm the
subscribe.
It take mail from stdin. Use it with postfix for example.
"""
# Do not use the ReplApplication.load_backends() method because we
# don't want to prompt user to create backend.
self.weboob.load_backends(names=[backend_name])
try:
backend = self.weboob.get_backend(backend_name)
except KeyError:
print >>sys.stderr, 'Error: backend "%s" not found.' % backend_name
return 1
if not backend.has_caps(ICapAccount):
print >>sys.stderr, 'Error: backend "%s" does not support accounts management' % backend_name
return 1
mail = sys.stdin.read()
if not backend.confirm_account(mail):
print >>sys.stderr, 'Error: Unable to confirm account creation'
return 1
return 0
def do_list(self, line):
"""
list

View file

@ -17,6 +17,8 @@
from __future__ import with_statement
import email
import re
import datetime
from dateutil import tz
@ -409,9 +411,32 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
country= account.properties['country'].value,
godfather= account.properties['godfather'].value)
except CaptchaError:
getLogger('aum').debug('Unable to resolve captcha. Retrying...')
getLogger('aum').info('Unable to resolve captcha. Retrying...')
browser = None
REGISTER_REGEXP = re.compile('.*http://www.adopteunmec.com/register4.php\?([^\' ]*)\'')
def confirm_account(self, mail):
msg = email.message_from_string(mail)
content = u''
for part in msg.walk():
s = part.get_payload(decode=True)
content += unicode(s, 'iso-8859-15')
url = None
for s in content.split():
m = self.REGISTER_REGEXP.match(s)
if m:
url = '/register4.php?' + m.group(1)
break
if url:
browser = self.BROWSER('')
browser.openurl(url)
return True
return False
def get_account(self):
"""
Get the current account.

View file

@ -47,6 +47,12 @@ class ICapAccount(IBaseCap):
"""
raise NotImplementedError()
def confirm_account(self, mail):
"""
From an email go to the confirm link.
"""
raise NotImplementedError()
def get_account(self):
"""
Get the current account.