use new Weboob.do function
This commit is contained in:
parent
926a25b992
commit
d42f1811d1
2 changed files with 43 additions and 25 deletions
|
|
@ -44,32 +44,45 @@ class Boobank(ConsoleApplication):
|
||||||
@ConsoleApplication.command('List every available accounts')
|
@ConsoleApplication.command('List every available accounts')
|
||||||
def command_list(self):
|
def command_list(self):
|
||||||
results = {'HEADER': ('ID', 'label', 'balance', 'coming')}
|
results = {'HEADER': ('ID', 'label', 'balance', 'coming')}
|
||||||
for backend in self.weboob.iter_backends():
|
try:
|
||||||
rows = []
|
for backend, account in self.weboob.do('iter_accounts'):
|
||||||
try:
|
row = [account.id, account.label, account.balance, account.coming]
|
||||||
for account in backend.iter_accounts():
|
try:
|
||||||
row = [account.id, account.label, account.balance, account.coming]
|
results[backend.name].append(row)
|
||||||
rows.append(row)
|
except KeyError:
|
||||||
except weboob.tools.browser.BrowserIncorrectPassword:
|
results[backend.name] = [row]
|
||||||
print >>sys.stderr, 'Error: Incorrect password for backend %s' % backend.name
|
except weboob.CallErrors, e:
|
||||||
return 1
|
for backend, error in e.errors:
|
||||||
results[backend.name] = rows
|
if isinstance(error, weboob.tools.browser.BrowserIncorrectPassword):
|
||||||
|
print >>sys.stderr, 'Error: Incorrect password for backend %s' % backend.name
|
||||||
|
else:
|
||||||
|
print >>sys.stderr, 'Error[%s]: %s' % (backend.name, error)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@ConsoleApplication.command('Display all future operations')
|
@ConsoleApplication.command('Display all future operations')
|
||||||
def command_coming(self, id):
|
def command_coming(self, id):
|
||||||
operations = []
|
operations = []
|
||||||
found = 0
|
found = 0
|
||||||
for backend in self.weboob.iter_backends():
|
total = 0.0
|
||||||
try:
|
|
||||||
account = backend.get_account(id)
|
def do(backend):
|
||||||
except AccountNotFound:
|
account = backend.get_account(id)
|
||||||
if found == 0:
|
return backend.iter_operations(account)
|
||||||
found = -1
|
|
||||||
else:
|
try:
|
||||||
|
for backend, operation in self.weboob.do(do):
|
||||||
found = 1
|
found = 1
|
||||||
for operation in backend.iter_operations(account):
|
operations.append(' %8s %-50s %11.2f' % (operation.date, operation.label, operation.amount))
|
||||||
operations.append(' %8s %-50s %11.2f' % (operation.date, operation.label, operation.amount))
|
total += operation.amount
|
||||||
|
except weboob.CallErrors, e:
|
||||||
|
for backend, error in e.errors:
|
||||||
|
if isinstance(error, AccountNotFound):
|
||||||
|
if not found:
|
||||||
|
found = -1
|
||||||
|
else:
|
||||||
|
print >>sys.stderr, 'Error[%s]: %s' % (backend.name, error)
|
||||||
|
|
||||||
if found < 0:
|
if found < 0:
|
||||||
print >>sys.stderr, "Error: account %s not found" % id
|
print >>sys.stderr, "Error: account %s not found" % id
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -78,5 +91,8 @@ class Boobank(ConsoleApplication):
|
||||||
print ' Date Label Amount '
|
print ' Date Label Amount '
|
||||||
print '+----------+----------------------------------------------------+-------------+'
|
print '+----------+----------------------------------------------------+-------------+'
|
||||||
print '\n'.join(operations)
|
print '\n'.join(operations)
|
||||||
|
print '+----------+----------------------------------------------------+-------------+'
|
||||||
|
print ' %8s %-50s %11.2f' % ('', 'Total:', total)
|
||||||
|
print '+----------+----------------------------------------------------+-------------+'
|
||||||
else:
|
else:
|
||||||
print 'No coming operations for ID=%s' % id
|
print 'No coming operations for ID=%s' % id
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from weboob.tools.application import PromptApplication
|
from weboob.tools.application import PromptApplication
|
||||||
from weboob.capabilities.dating import ICapDating
|
from weboob.capabilities.dating import ICapDating
|
||||||
|
|
@ -53,19 +55,19 @@ class HaveSex(PromptApplication):
|
||||||
if not backend:
|
if not backend:
|
||||||
print 'Invalid ID: %s' % id
|
print 'Invalid ID: %s' % id
|
||||||
return False
|
return False
|
||||||
profile = backend.get_profile(_id)
|
with backend:
|
||||||
if not profile:
|
profile = backend.get_profile(_id)
|
||||||
print 'Profile not found'
|
if not profile:
|
||||||
|
print 'Profile not found'
|
||||||
|
|
||||||
print profile.get_profile_text()
|
print profile.get_profile_text()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def service(self, action, function):
|
def service(self, action, function):
|
||||||
sys.stdout.write('%s:' % action)
|
sys.stdout.write('%s:' % action)
|
||||||
for backend in self.weboob.iter_backends():
|
for backend, result in self.weboob.do(function):
|
||||||
sys.stdout.write(' ' + backend.name)
|
sys.stdout.write(' ' + backend.name)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
getattr(backend, function)()
|
|
||||||
sys.stdout.write('.\n')
|
sys.stdout.write('.\n')
|
||||||
|
|
||||||
@PromptApplication.command("start profiles walker")
|
@PromptApplication.command("start profiles walker")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue