本文整理汇总了Python中weboob.core.Weboob.build_backend方法的典型用法代码示例。如果您正苦于以下问题:Python Weboob.build_backend方法的具体用法?Python Weboob.build_backend怎么用?Python Weboob.build_backend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weboob.core.Weboob
的用法示例。
在下文中一共展示了Weboob.build_backend方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import build_backend [as 别名]
def main(filename):
weboob = Weboob()
try:
hds = weboob.build_backend('hds')
except ModuleLoadError, e:
print >>sys.stderr, 'Unable to load "hds" module: %s' % e
return 1
示例2: BackendTest
# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import build_backend [as 别名]
class BackendTest(TestCase):
MODULE = None
def __init__(self, *args, **kwargs):
super(BackendTest, self).__init__(*args, **kwargs)
self.backends = {}
self.backend_instance = None
self.backend = None
self.weboob = Weboob()
# Skip tests when passwords are missing
self.weboob.requests.register('login', self.login_cb)
if self.weboob.load_backends(modules=[self.MODULE]):
# provide the tests with all available backends
self.backends = self.weboob.backend_instances
def login_cb(self, backend_name, value):
raise SkipTest('missing config \'%s\' is required for this test' % value.label)
def run(self, result):
"""
Call the parent run() for each backend instance.
Skip the test if we have no backends.
"""
# This is a hack to fix an issue with nosetests running
# with many tests. The default is 1000.
sys.setrecursionlimit(10000)
try:
if not len(self.backends):
self.backend = self.weboob.build_backend(self.MODULE, nofail=True)
TestCase.run(self, result)
else:
# Run for all backend
for backend_instance in self.backends.keys():
print(backend_instance)
self.backend = self.backends[backend_instance]
TestCase.run(self, result)
finally:
self.weboob.deinit()
def shortDescription(self):
"""
Generate a description with the backend instance name.
"""
# do not use TestCase.shortDescription as it returns None
return '%s [%s]' % (str(self), self.backend_instance)
def is_backend_configured(self):
"""
Check if the backend is in the user configuration file
"""
return self.weboob.backends_config.backend_exists(self.backend.config.instname)
示例3: main
# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import build_backend [as 别名]
def main(filename):
weboob = Weboob()
try:
hds = weboob.build_backend('hds')
except ModuleLoadError as e:
print('Unable to load "hds" module: %s' % e, file=sys.stderr)
return 1
try:
db = sqlite.connect(database=filename, timeout=10.0)
except sqlite.OperationalError as err:
print('Unable to open %s database: %s' % (filename, err), file=sys.stderr)
return 1
sys.stdout.write('Reading database... ')
sys.stdout.flush()
try:
results = db.execute('SELECT id, author FROM stories')
except sqlite.OperationalError as err:
print('fail!\nUnable to read database: %s' % err, file=sys.stderr)
return 1
stored = set()
authors = set()
for r in results:
stored.add(r[0])
authors.add(r[1])
stored_authors = set([s[0] for s in db.execute('SELECT name FROM authors')])
sys.stdout.write('ok\n')
br = hds.browser
to_fetch = set()
sys.stdout.write('Getting stories list from website... ')
sys.stdout.flush()
for story in br.iter_stories():
if int(story.id) in stored:
break
to_fetch.add(story.id)
authors.add(story.author.name)
sys.stdout.write(' ok\n')
sys.stdout.write('Getting %d new storiese... ' % len(to_fetch))
sys.stdout.flush()
for id in to_fetch:
story = br.get_story(id)
if not story:
logging.warning('Story #%d unavailable' % id)
continue
db.execute("""INSERT INTO stories (id, title, date, category, author, body)
VALUES (?, ?, ?, ?, ?, ?)""",
(story.id, story.title, story.date, story.category,
story.author.name, story.body))
db.commit()
sys.stdout.write('ok\n')
authors = authors.difference(stored_authors)
sys.stdout.write('Getting %d new authors... ' % len(authors))
sys.stdout.flush()
for a in authors:
author = br.get_author(a)
if not author:
logging.warning('Author %s unavailable\n' % id)
continue
db.execute("INSERT INTO authors (name, sex, description) VALUES (?, ?, ?)",
(a, author.sex, author.description))
db.commit()
sys.stdout.write(' ok\n')
return 0
示例4: Connector
# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import build_backend [as 别名]
#.........这里部分代码省略.........
"""
Create a Weboob backend for a given module, ready to be used to fetch
data.
:param modulename: The name of the module from which backend should be
created.
:param parameters: A dict of parameters to pass to the module. It
should at least contain ``login`` and ``password`` fields, but can
contain additional values depending on the module.
:param session: an object representing the browser state.
"""
# Install the module if required.
repositories = self.weboob.repositories
minfo = repositories.get_module_info(modulename)
if (
minfo is not None and not minfo.is_installed() and
not minfo.is_local()
):
# We cannot install a locally available module, this would
# result in a ModuleInstallError.
try:
repositories.install(minfo, progress=DummyProgress())
except ModuleInstallError:
fail(
GENERIC_EXCEPTION,
"Unable to install module %s." % modulename,
traceback.format_exc()
)
# Initialize the Storage.
self.storage = DictStorage(session)
# Initialize the backend.
self.backend = self.weboob.build_backend(
modulename,
parameters,
storage=self.storage
)
def delete_backend(self):
"""
Delete a created backend for the given module.
"""
if self.backend:
with self.backend:
self.backend.deinit()
self.backend = None
self.storage = None
def get_accounts(self):
"""
Fetch accounts data from Weboob.
:param backend: The Weboob built backend to fetch data from.
:returns: A list of dicts representing the available accounts.
"""
results = []
with self.backend:
for account in list(self.backend.iter_accounts()):
# The minimum dict keys for an account are :
# 'id', 'label', 'balance' and 'type'
# Retrieve extra information for the account.
account = self.backend.fillobj(account, ['iban', 'currency'])