use formatters

This commit is contained in:
Christophe Benz 2010-04-20 21:34:40 +02:00
commit 81c416cd6e
2 changed files with 27 additions and 29 deletions

View file

@ -28,31 +28,31 @@ import weboob
from weboob.capabilities.bank import ICapBank, AccountNotFound
from weboob.tools.application import ConsoleApplication
__all__ = ['Boobank']
class Boobank(ConsoleApplication):
APPNAME = 'boobank'
def main(self, argv):
self.weboob.load_backends(ICapBank)
self.weboob.load_backends(ICapBank, names=self.enabled_backends)
return self.process_command(*argv[1:])
@ConsoleApplication.command('List every available accounts')
def command_list(self):
accounts = []
results = {'HEADER': ('ID', 'label', 'balance', 'coming')}
for backend in self.weboob.iter_backends():
rows = []
try:
for account in backend.iter_accounts():
accounts.append('%17s %-20s %11.2f %11.2f' % (
account.id, account.label, account.balance, account.coming))
row = [account.id, account.label, account.balance, account.coming]
rows.append(row)
except weboob.tools.browser.BrowserIncorrectPassword:
print >>sys.stderr, 'Error: Incorrect password for backend %s' % backend.name
return 1
if len(accounts):
print ' ID Account Balance Coming '
print '+-----------------+---------------------+--------------+-------------+'
print '\n'.join(accounts)
else:
print 'No accounts found'
results[backend.name] = rows
return results
@ConsoleApplication.command('Display all future operations')
def command_coming(self, id):
@ -78,6 +78,3 @@ class Boobank(ConsoleApplication):
print '\n'.join(operations)
else:
print 'No coming operations for ID=%s' % id
if __name__ == '__main__':
Boobank.run()

View file

@ -36,43 +36,44 @@ class Videoob(ConsoleApplication):
video = backend.get_video(_id)
if video is None:
continue
result = []
rows = []
rows.append(('ID', video.id))
if video.title:
result.append(('Video title', video.title))
rows.append(('Video title', video.title))
if video.duration:
result.append(('Duration', '%d:%02d:%02d' % (
rows.append(('Duration', '%d:%02d:%02d' % (
video.duration / 3600, (video.duration % 3600) / 60, video.duration % 60)))
if video.url:
result.append(('URL', video.url))
rows.append(('URL', video.url))
if video.author:
result.append(('Author', video.author))
rows.append(('Author', video.author))
if video.date:
result.append(('Date', video.date))
rows.append(('Date', video.date))
if video.rating_max:
result.append(('Rating', '%s / %s' % (video.rating, video.rating_max)))
rows.append(('Rating', '%s / %s' % (video.rating, video.rating_max)))
elif video.rating:
result.append(('Rating', video.rating))
results[backend.name] = result
rows.append(('Rating', video.rating))
results[backend.name] = rows
return results
@ConsoleApplication.command('Search videos')
def command_search(self, pattern=None):
results = {}
if pattern:
results['HEADER'] = u'Search pattern: %s' % pattern
results['BEFORE'] = u'Search pattern: %s' % pattern
else:
results['HEADER'] = u'Last videos'
results['BEFORE'] = u'Last videos'
for backend in self.weboob.iter_backends():
result = []
try:
iterator = backend.iter_search_results(pattern)
except NotImplementedError:
continue
else:
rows = []
for video in iterator:
result.append(('ID', video.id))
result.append(('Title', video.title))
results[backend.name] = result
rows.append(('ID', video.id))
rows.append(('Title', video.title))
results[backend.name] = rows
return results
@ConsoleApplication.command('Get video file URL from page URL')