adapt frontends to new Results API
This commit is contained in:
parent
e0eddf0299
commit
7d698192f3
4 changed files with 34 additions and 126 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright(C) 2009-2010 Romain Bignon
|
Copyright(C) 2009-2010 Romain Bignon, Christophe Benz
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import weboob
|
import weboob
|
||||||
|
|
@ -43,27 +44,18 @@ 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')}
|
|
||||||
try:
|
try:
|
||||||
for backend, account in self.weboob.do('iter_accounts'):
|
for backend, account in self.weboob.do('iter_accounts'):
|
||||||
row = [account.id, account.label, account.balance, account.coming]
|
print self.format(account)
|
||||||
try:
|
|
||||||
results[backend.name].append(row)
|
|
||||||
except KeyError:
|
|
||||||
results[backend.name] = [row]
|
|
||||||
except weboob.CallErrors, e:
|
except weboob.CallErrors, e:
|
||||||
for backend, error in e.errors:
|
for backend, error in e.errors:
|
||||||
if isinstance(error, weboob.tools.browser.BrowserIncorrectPassword):
|
if isinstance(error, weboob.tools.browser.BrowserIncorrectPassword):
|
||||||
print >>sys.stderr, 'Error: Incorrect password for backend %s' % backend.name
|
logging.error(u'Error: Incorrect password for backend %s' % backend.name)
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'Error[%s]: %s' % (backend.name, error)
|
logging.error(u'Error[%s]: %s' % (backend.name, error))
|
||||||
|
|
||||||
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 = []
|
|
||||||
found = 0
|
|
||||||
total = 0.0
|
total = 0.0
|
||||||
|
|
||||||
def do(backend):
|
def do(backend):
|
||||||
|
|
@ -72,27 +64,11 @@ class Boobank(ConsoleApplication):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for backend, operation in self.weboob.do(do):
|
for backend, operation in self.weboob.do(do):
|
||||||
found = 1
|
print self.format(operation)
|
||||||
operations.append(' %8s %-50s %11.2f' % (operation.date, operation.label, operation.amount))
|
|
||||||
total += operation.amount
|
total += operation.amount
|
||||||
except weboob.CallErrors, e:
|
except weboob.CallErrors, e:
|
||||||
for backend, error in e.errors:
|
for backend, error in e.errors:
|
||||||
if isinstance(error, AccountNotFound):
|
if isinstance(error, AccountNotFound):
|
||||||
if not found:
|
logging.error(u'Error: account %s not found' % id)
|
||||||
found = -1
|
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'Error[%s]: %s' % (backend.name, error)
|
logging.error(u'Error[%s]: %s' % (backend.name, error))
|
||||||
|
|
||||||
if found < 0:
|
|
||||||
print >>sys.stderr, "Error: account %s not found" % id
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
if operations:
|
|
||||||
print ' Date Label Amount '
|
|
||||||
print '+----------+----------------------------------------------------+-------------+'
|
|
||||||
print '\n'.join(operations)
|
|
||||||
print '+----------+----------------------------------------------------+-------------+'
|
|
||||||
print ' %8s %-50s %11.2f' % ('', 'Total:', total)
|
|
||||||
print '+----------+----------------------------------------------------+-------------+'
|
|
||||||
else:
|
|
||||||
print 'No coming operations for ID=%s' % id
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
from weboob.capabilities.travel import ICapTravel
|
from weboob.capabilities.travel import ICapTravel
|
||||||
from weboob.tools.application import ConsoleApplication
|
from weboob.tools.application import ConsoleApplication
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['Travel']
|
||||||
|
|
||||||
|
|
||||||
class Travel(ConsoleApplication):
|
class Travel(ConsoleApplication):
|
||||||
APPNAME = 'travel'
|
APPNAME = 'travel'
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
|
|
@ -33,34 +37,10 @@ class Travel(ConsoleApplication):
|
||||||
|
|
||||||
@ConsoleApplication.command('Search stations')
|
@ConsoleApplication.command('Search stations')
|
||||||
def command_stations(self, pattern):
|
def command_stations(self, pattern):
|
||||||
print ".--------------------------------.---------------------------------------------."
|
for backend, station in self.weboob.do('iter_station_search', pattern):
|
||||||
print '| ID | Name |'
|
print self.format(station)
|
||||||
print '+--------------------------------+---------------------------------------------+'
|
|
||||||
count = 0
|
|
||||||
for backend in self.weboob.iter_backends():
|
|
||||||
for station in backend.iter_station_search(pattern):
|
|
||||||
print '| %-31s| %-44s|' % (station.id, station.name)
|
|
||||||
count += 1
|
|
||||||
print "+--------------------------------'---------------------------------------------+"
|
|
||||||
print "| %3d stations listed |" % count
|
|
||||||
print "'------------------------------------------------------------------------------'"
|
|
||||||
|
|
||||||
@ConsoleApplication.command('List all departures on a special station')
|
@ConsoleApplication.command('List all departures on a special station')
|
||||||
def command_departures(self, station, arrival=None):
|
def command_departures(self, station, arrival=None):
|
||||||
print ".-----.-----------.-------.-----------------------.-------.--------------------.------------"
|
for backend, departure in self.weboob.do('iter_station_departures', station, arrival):
|
||||||
print "| ID | Type | Time | Arrival | Late | Info | Plateform |"
|
print self.format(departure)
|
||||||
print "+-----+-----------+-------+-----------------------+-------+--------------------+-----------+"
|
|
||||||
count = 0
|
|
||||||
for backend in self.weboob.iter_backends():
|
|
||||||
for departure in backend.iter_station_departures(station, arrival):
|
|
||||||
print u"|%4d | %-10s|%6s | %-22s|%6s | %-19s| %-10s|" % (departure.id,
|
|
||||||
departure.type,
|
|
||||||
departure.time.strftime("%H:%M"),
|
|
||||||
departure.arrival_station,
|
|
||||||
departure.late and departure.late.strftime("%H:%M") or '',
|
|
||||||
departure.information,
|
|
||||||
departure.plateform)
|
|
||||||
count += 1
|
|
||||||
print "+-----'-----------'-------'-----------------------'-------'--------------------'-----------+"
|
|
||||||
print "| %3d departures listed |" % count
|
|
||||||
print "'------------------------------------------------------------------------------------------'"
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from weboob.capabilities.torrent import ICapTorrent
|
from weboob.capabilities.torrent import ICapTorrent
|
||||||
from weboob.tools.application import ConsoleApplication
|
from weboob.tools.application import ConsoleApplication
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['Weboorrents']
|
||||||
|
|
||||||
|
|
||||||
class Weboorrents(ConsoleApplication):
|
class Weboorrents(ConsoleApplication):
|
||||||
APPNAME = 'weboorrents'
|
APPNAME = 'weboorrents'
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
|
|
@ -37,13 +42,13 @@ class Weboorrents(ConsoleApplication):
|
||||||
|
|
||||||
def split_id(self, id):
|
def split_id(self, id):
|
||||||
if not '.' in id:
|
if not '.' in id:
|
||||||
print >>sys.stderr, 'ID must be in form <backend>.<ID>'
|
logging.error('ID must be in form <backend>.<ID>')
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
backend_name, id = id.split('.', 1)
|
backend_name, id = id.split('.', 1)
|
||||||
backend = self.weboob.backends.get(backend_name, None)
|
backend = self.weboob.backends.get(backend_name, None)
|
||||||
if not backend:
|
if not backend:
|
||||||
print >>sys.stderr, 'Backends "%s" not found' % backend_name
|
logging.error('Backends "%s" not found' % backend_name)
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
return backend, id
|
return backend, id
|
||||||
|
|
@ -53,25 +58,12 @@ class Weboorrents(ConsoleApplication):
|
||||||
backend, id = self.split_id(id)
|
backend, id = self.split_id(id)
|
||||||
if not backend:
|
if not backend:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
with backend:
|
with backend:
|
||||||
torrent = backend.get_torrent(id)
|
torrent = backend.get_torrent(id)
|
||||||
|
|
||||||
if not torrent:
|
if not torrent:
|
||||||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
logging.error('Torrent "%s" not found' % id)
|
||||||
return 1
|
return 1
|
||||||
|
print self.format(torrent)
|
||||||
rows = []
|
|
||||||
rows.append(('ID', torrent.id))
|
|
||||||
rows.append(('Name', torrent.name))
|
|
||||||
rows.append(('Size', torrent.size))
|
|
||||||
rows.append(('URL', torrent.url))
|
|
||||||
rows.append(('Seeders', torrent.seeders))
|
|
||||||
rows.append(('Leechers', torrent.leechers))
|
|
||||||
rows.append(('Description', torrent.description))
|
|
||||||
if torrent.files:
|
|
||||||
rows.append(('Files', '\n'.join(torrent.files)))
|
|
||||||
return {backend.name: rows}
|
|
||||||
|
|
||||||
@ConsoleApplication.command('Get the torrent file')
|
@ConsoleApplication.command('Get the torrent file')
|
||||||
def command_getfile(self, id, dest):
|
def command_getfile(self, id, dest):
|
||||||
|
|
@ -82,7 +74,7 @@ class Weboorrents(ConsoleApplication):
|
||||||
with backend:
|
with backend:
|
||||||
s = backend.get_torrent_file(id)
|
s = backend.get_torrent_file(id)
|
||||||
if not s:
|
if not s:
|
||||||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
logging.error('Torrent "%s" not found' % id)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if dest == '-':
|
if dest == '-':
|
||||||
|
|
@ -93,17 +85,6 @@ class Weboorrents(ConsoleApplication):
|
||||||
|
|
||||||
@ConsoleApplication.command('Search torrents')
|
@ConsoleApplication.command('Search torrents')
|
||||||
def command_search(self, pattern=None):
|
def command_search(self, pattern=None):
|
||||||
results = {}
|
print u'Search pattern: %s' % pattern if pattern else u'Last torrents'
|
||||||
if pattern:
|
|
||||||
results['BEFORE'] = u'Search pattern: %s' % pattern
|
|
||||||
else:
|
|
||||||
results['BEFORE'] = u'Last videos'
|
|
||||||
results['HEADER'] = ('ID', 'Name', 'Size')
|
|
||||||
|
|
||||||
for backend, torrent in self.weboob.do('iter_torrents', pattern=pattern):
|
for backend, torrent in self.weboob.do('iter_torrents', pattern=pattern):
|
||||||
row = ('%s.%s' % (backend.name,torrent.id), torrent.name, torrent.size)
|
print self.format(torrent)
|
||||||
try:
|
|
||||||
results[backend.name].append(row)
|
|
||||||
except KeyError:
|
|
||||||
results[backend.name] = [row]
|
|
||||||
return results
|
|
||||||
|
|
|
||||||
|
|
@ -34,58 +34,29 @@ class WetBoobs(ConsoleApplication):
|
||||||
|
|
||||||
@ConsoleApplication.command('search cities')
|
@ConsoleApplication.command('search cities')
|
||||||
def command_search(self, pattern):
|
def command_search(self, pattern):
|
||||||
print ".--------------------------------.---------------------------------------------."
|
|
||||||
print '| ID | Name |'
|
|
||||||
print '+--------------------------------+---------------------------------------------+'
|
|
||||||
count = 0
|
|
||||||
for backend, city in self.weboob.do('iter_city_search', pattern):
|
for backend, city in self.weboob.do('iter_city_search', pattern):
|
||||||
print u'| %-31s| %-44s|' % (city.city_id, city.name)
|
print self.format(city)
|
||||||
count += 1
|
|
||||||
print "+--------------------------------'---------------------------------------------+"
|
|
||||||
print "| %3d cities listed |" % count
|
|
||||||
print "'------------------------------------------------------------------------------'"
|
|
||||||
|
|
||||||
@ConsoleApplication.command('get current weather')
|
@ConsoleApplication.command('get current weather')
|
||||||
def command_current(self, city):
|
def command_current(self, city):
|
||||||
print ".-------------.----------------------------------------------------------------."
|
|
||||||
print '| Temperature | Text |'
|
|
||||||
print '+-------------+----------------------------------------------------------------+'
|
|
||||||
found = 0
|
|
||||||
try:
|
try:
|
||||||
for backend, current in self.weboob.do('get_current', city):
|
for backend, current in self.weboob.do('get_current', city):
|
||||||
print u'| %-12s| %-63s|' % (u'%d °%s' % (current.temp, current.unit), current.text)
|
print self.format(current)
|
||||||
found = 1
|
|
||||||
except CallErrors, e:
|
except CallErrors, e:
|
||||||
for error in e:
|
for error in e:
|
||||||
if isinstance(error, CityNotFound):
|
if isinstance(error, CityNotFound):
|
||||||
if not found:
|
logging.error('City "%s" not found' % city)
|
||||||
found = -1
|
|
||||||
else:
|
else:
|
||||||
raise error
|
raise error
|
||||||
if found < 0:
|
|
||||||
print "| -- | City not found |"
|
|
||||||
print "+-------------'----------------------------------------------------------------+"
|
|
||||||
|
|
||||||
@ConsoleApplication.command('get forecasts')
|
@ConsoleApplication.command('get forecasts')
|
||||||
def command_forecasts(self, city):
|
def command_forecasts(self, city):
|
||||||
print ".-------------.------.------.--------------------------------------------------."
|
|
||||||
print '| Date | Min | Max | Text |'
|
|
||||||
print '+-------------+-------+-------+------------------------------------------------+'
|
|
||||||
found = 0
|
|
||||||
try:
|
try:
|
||||||
for backend, f in self.weboob.do('iter_forecast', city):
|
for backend, forecast in self.weboob.do('iter_forecast', city):
|
||||||
found = 1
|
print self.format(forecast)
|
||||||
print u'| %-12s|%6s |%6s | %-47s|' % (f.date,
|
|
||||||
u'%d °%s' % (f.low, f.unit),
|
|
||||||
u'%d °%s' % (f.high, f.unit),
|
|
||||||
f.text)
|
|
||||||
except CallErrors, e:
|
except CallErrors, e:
|
||||||
for error in e:
|
for error in e:
|
||||||
if isinstance(error, CityNotFound):
|
if isinstance(error, CityNotFound):
|
||||||
if not found:
|
logging.error('City "%s" not found' % city)
|
||||||
found = -1
|
|
||||||
else:
|
else:
|
||||||
raise error
|
raise error
|
||||||
if found < 0:
|
|
||||||
print "| -- --- ---- | -- | -- | City not found |"
|
|
||||||
print "+-------------'-------'-------'------------------------------------------------+"
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue