improve the dummy script
This commit is contained in:
parent
2cb52beba5
commit
3d0c80c323
5 changed files with 24 additions and 11 deletions
|
|
@ -22,22 +22,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
from weboob import Weboob
|
from weboob import Weboob
|
||||||
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
|
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
|
||||||
|
from weboob.capabilities.travel import ICapTravel
|
||||||
from weboob.tools.application import BaseApplication
|
from weboob.tools.application import BaseApplication
|
||||||
|
|
||||||
class Application(BaseApplication):
|
class Application(BaseApplication):
|
||||||
APPNAME = 'dummy'
|
APPNAME = 'dummy'
|
||||||
|
|
||||||
def main(self, argv):
|
def main(self, argv):
|
||||||
self.weboob.load_backends()
|
if not self.weboob.load_backends():
|
||||||
|
self.weboob.load_modules()
|
||||||
|
|
||||||
for name, backend in self.weboob.iter_backends():
|
for name, backend in self.weboob.iter_backends():
|
||||||
print '= Processing backend name = %s' % name
|
print 'Backend [%s]' % name
|
||||||
if backend.has_caps(ICapMessages):
|
if backend.has_caps(ICapMessages):
|
||||||
print '== Backend is ICapMessages => print its messages'
|
print '|- ICapMessages [Print its messages]'
|
||||||
for message in backend.iter_messages():
|
for message in backend.iter_messages():
|
||||||
print '=== %s' % message
|
print '| |- %s' % message
|
||||||
if backend.has_caps(ICapMessagesReply):
|
if backend.has_caps(ICapMessagesReply):
|
||||||
print '== Backend is ICapMessagesReply => TODO'
|
print '|- ICapMessagesReply [TODO]'
|
||||||
|
if backend.has_caps(ICapTravel):
|
||||||
|
print '|- ICapTravel.stations [Search station \'defense\']'
|
||||||
|
s = None
|
||||||
|
for station in backend.iter_station_search('defense'):
|
||||||
|
print '| |- [%s] %s' % (station.id, station.name)
|
||||||
|
if s is None:
|
||||||
|
s = station.id
|
||||||
|
print '|- ICapTravel.departures [Departures from \'%s\']' % s
|
||||||
|
for departure in backend.iter_station_departures(s):
|
||||||
|
print '| |- [%s] %s at %s to %s' % (departure.id, departure.type, departure.time.strftime("%H:%M"), departure.arrival_station)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Application.run()
|
Application.run()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright(C) 2010 Romain Bignon
|
Copyright(C) 2010 Romain Bignon
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,11 @@ class Weboob:
|
||||||
|
|
||||||
def load_backends(self, caps=None, names=None):
|
def load_backends(self, caps=None, names=None):
|
||||||
self.backends.update(self.modules_loader.load_backends(self.get_backends_filename(), caps, names))
|
self.backends.update(self.modules_loader.load_backends(self.get_backends_filename(), caps, names))
|
||||||
|
return self.backends
|
||||||
|
|
||||||
def load_modules(self, caps=None, names=None):
|
def load_modules(self, caps=None, names=None):
|
||||||
self.backends.update(self.modules_loader.load_modules_as_backends(caps, names))
|
self.backends.update(self.modules_loader.load_modules_as_backends(caps, names))
|
||||||
|
return self.backends
|
||||||
|
|
||||||
def iter_backends(self, caps=None):
|
def iter_backends(self, caps=None):
|
||||||
for name, backend in self.backends.iteritems():
|
for name, backend in self.backends.iteritems():
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright(C) 2010 Romain Bignon
|
Copyright(C) 2010 Romain Bignon
|
||||||
|
|
@ -26,8 +24,11 @@ import re
|
||||||
from weboob import Weboob
|
from weboob import Weboob
|
||||||
|
|
||||||
class BaseApplication(object):
|
class BaseApplication(object):
|
||||||
|
# Application name
|
||||||
APPNAME = ''
|
APPNAME = ''
|
||||||
|
# Default configuration
|
||||||
CONFIG = {}
|
CONFIG = {}
|
||||||
|
# Configuration directory
|
||||||
CONFDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
CONFDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ else:
|
||||||
return HTMLParser.parse(data, encoding='iso-8859-1')
|
return HTMLParser.parse(data, encoding='iso-8859-1')
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from logging import warning, error
|
from logging import warning, error, debug
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -220,7 +220,7 @@ class Browser(mechanize.Browser):
|
||||||
warning('Ho my fucking god, there isn\'t any page named %s' % result.geturl())
|
warning('Ho my fucking god, there isn\'t any page named %s' % result.geturl())
|
||||||
return
|
return
|
||||||
|
|
||||||
print '[%s] Gone on %s' % (self.username, result.geturl())
|
debug('[%s] Gone on %s' % (self.username, result.geturl()))
|
||||||
self.last_update = time.time()
|
self.last_update = time.time()
|
||||||
|
|
||||||
document = self.__parser.parse(result)
|
document = self.__parser.parse(result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue