new command 'weboob-config confirm'
This commit is contained in:
parent
d224effe35
commit
01acc2c7d4
3 changed files with 63 additions and 1 deletions
|
|
@ -17,9 +17,11 @@
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from weboob.capabilities.account import ICapAccount
|
||||||
from weboob.tools.application.repl import ReplApplication
|
from weboob.tools.application.repl import ReplApplication
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
|
|
||||||
|
|
@ -70,6 +72,35 @@ class WeboobCfg(ReplApplication):
|
||||||
"""
|
"""
|
||||||
self.register_backend(line)
|
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):
|
def do_list(self, line):
|
||||||
"""
|
"""
|
||||||
list
|
list
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
import email
|
||||||
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
from dateutil import tz
|
from dateutil import tz
|
||||||
|
|
||||||
|
|
@ -409,9 +411,32 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
|
||||||
country= account.properties['country'].value,
|
country= account.properties['country'].value,
|
||||||
godfather= account.properties['godfather'].value)
|
godfather= account.properties['godfather'].value)
|
||||||
except CaptchaError:
|
except CaptchaError:
|
||||||
getLogger('aum').debug('Unable to resolve captcha. Retrying...')
|
getLogger('aum').info('Unable to resolve captcha. Retrying...')
|
||||||
browser = None
|
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):
|
def get_account(self):
|
||||||
"""
|
"""
|
||||||
Get the current account.
|
Get the current account.
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,12 @@ class ICapAccount(IBaseCap):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def confirm_account(self, mail):
|
||||||
|
"""
|
||||||
|
From an email go to the confirm link.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def get_account(self):
|
def get_account(self):
|
||||||
"""
|
"""
|
||||||
Get the current account.
|
Get the current account.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue