PyLint check
This commit is contained in:
parent
ee677ab6d2
commit
b242fc37b1
@ -13,8 +13,9 @@ import logging
|
|||||||
from weboob.core import Weboob
|
from weboob.core import Weboob
|
||||||
from weboob.exceptions import ModuleInstallError
|
from weboob.exceptions import ModuleInstallError
|
||||||
|
|
||||||
from tools.progress import DummyProgress
|
import cozyweboob.tools.weboob_tools as weboob_tools
|
||||||
import tools.weboob_tools as weboob_tools
|
|
||||||
|
from cozyweboob.tools.progress import DummyProgress
|
||||||
|
|
||||||
|
|
||||||
# Module specific logger
|
# Module specific logger
|
||||||
@ -68,13 +69,13 @@ class WeboobProxy(object):
|
|||||||
# Install modules if required
|
# Install modules if required
|
||||||
for infos in modules.values():
|
for infos in modules.values():
|
||||||
if infos is not None and (
|
if infos is not None and (
|
||||||
not infos.is_installed() or
|
not infos.is_installed() or
|
||||||
not infos.is_local()
|
not infos.is_local()
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
repositories.install(infos, progress=DummyProgress())
|
repositories.install(infos, progress=DummyProgress())
|
||||||
except ModuleInstallError as e:
|
except ModuleInstallError as exception:
|
||||||
logger.info(str(e))
|
logger.info(str(exception))
|
||||||
return {
|
return {
|
||||||
module_name: dict(infos.dump())
|
module_name: dict(infos.dump())
|
||||||
for module_name, infos in modules.items()
|
for module_name, infos in modules.items()
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
from WeboobProxy import WeboobProxy
|
"""
|
||||||
from __main__ import main_fetch, main
|
CozyWeboob main module
|
||||||
|
"""
|
||||||
|
from cozyweboob.WeboobProxy import WeboobProxy
|
||||||
|
from cozyweboob.__main__ import main_fetch, main
|
||||||
|
|
||||||
__all__ = ["WeboobProxy", "main_fetch", "main"]
|
__all__ = ["WeboobProxy", "main_fetch", "main"]
|
||||||
|
@ -13,9 +13,9 @@ from getpass import getpass
|
|||||||
|
|
||||||
from requests.utils import dict_from_cookiejar
|
from requests.utils import dict_from_cookiejar
|
||||||
|
|
||||||
from WeboobProxy import WeboobProxy
|
from cozyweboob.WeboobProxy import WeboobProxy
|
||||||
from tools.env import is_in_debug_mode
|
from cozyweboob.tools.env import is_in_debug_mode
|
||||||
from tools.jsonwriter import pretty_json
|
from cozyweboob.tools.jsonwriter import pretty_json
|
||||||
|
|
||||||
|
|
||||||
# Module specific logger
|
# Module specific logger
|
||||||
@ -67,7 +67,10 @@ def main_fetch(used_modules):
|
|||||||
fetching_function(
|
fetching_function(
|
||||||
backend,
|
backend,
|
||||||
# If no actions specified, fetch but don't download
|
# If no actions specified, fetch but don't download
|
||||||
module.get("actions", {"fetch": True, "download": False})
|
module.get("actions", {
|
||||||
|
"fetch": True,
|
||||||
|
"download": False
|
||||||
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -83,9 +86,9 @@ def main_fetch(used_modules):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Avoid an AttributeError if no session is used for this module
|
# Avoid an AttributeError if no session is used for this module
|
||||||
fetched_data[module["id"]]["cookies"] = None
|
fetched_data[module["id"]]["cookies"] = None
|
||||||
except Exception as e:
|
except Exception as exception:
|
||||||
# Store any error happening in a dedicated field
|
# Store any error happening in a dedicated field
|
||||||
fetched_data[module["id"]]["error"] = e
|
fetched_data[module["id"]]["error"] = exception
|
||||||
if is_in_debug_mode():
|
if is_in_debug_mode():
|
||||||
# Reraise if in debug
|
# Reraise if in debug
|
||||||
raise
|
raise
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
This module contains all the conversion functions associated to the Document
|
This module contains all the conversion functions associated to the Document
|
||||||
capability.
|
capability.
|
||||||
"""
|
"""
|
||||||
from base import clean_object
|
from cozyweboob.capabilities.base import clean_object
|
||||||
from weboob.capabilities.bill import Bill
|
from weboob.capabilities.bill import Bill
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +34,8 @@ def fetch_documents(document, subscriptions):
|
|||||||
subscriptions: A list of subscriptions for the CapDocument object.
|
subscriptions: A list of subscriptions for the CapDocument object.
|
||||||
Returns: A tuple of cleaned list of documents and bills.
|
Returns: A tuple of cleaned list of documents and bills.
|
||||||
"""
|
"""
|
||||||
|
# Get the BASEURL to generate absolute URLs
|
||||||
|
base_url = document.browser.BASEURL
|
||||||
try:
|
try:
|
||||||
assert subscriptions
|
assert subscriptions
|
||||||
raw_documents = {
|
raw_documents = {
|
||||||
@ -41,7 +43,9 @@ def fetch_documents(document, subscriptions):
|
|||||||
for subscription in subscriptions
|
for subscription in subscriptions
|
||||||
}
|
}
|
||||||
raw_bills = {
|
raw_bills = {
|
||||||
subscription: [bill for bill in documents if isinstance(bill, Bill)]
|
subscription: [
|
||||||
|
bill for bill in documents if isinstance(bill, Bill)
|
||||||
|
]
|
||||||
for subscription, documents in raw_documents.items()
|
for subscription, documents in raw_documents.items()
|
||||||
}
|
}
|
||||||
bills = {
|
bills = {
|
||||||
@ -54,7 +58,8 @@ def fetch_documents(document, subscriptions):
|
|||||||
documents = {
|
documents = {
|
||||||
subscription: [
|
subscription: [
|
||||||
clean_object(bill, base_url=base_url)
|
clean_object(bill, base_url=base_url)
|
||||||
for bill in documents_list if bill not in raw_bills[subscription]
|
for bill in documents_list
|
||||||
|
if bill not in raw_bills[subscription]
|
||||||
]
|
]
|
||||||
for subscription, documents_list in raw_documents.items()
|
for subscription, documents_list in raw_documents.items()
|
||||||
}
|
}
|
||||||
@ -77,6 +82,8 @@ def fetch_details(document, subscriptions):
|
|||||||
subscriptions: A list of subscriptions for the CapDocument object.
|
subscriptions: A list of subscriptions for the CapDocument object.
|
||||||
Returns: A cleaned list of detailed bills.
|
Returns: A cleaned list of detailed bills.
|
||||||
"""
|
"""
|
||||||
|
# Get the BASEURL to generate absolute URLs
|
||||||
|
base_url = document.browser.BASEURL
|
||||||
try:
|
try:
|
||||||
assert subscriptions
|
assert subscriptions
|
||||||
detailed_bills = {
|
detailed_bills = {
|
||||||
@ -103,6 +110,8 @@ def fetch_history(document, subscriptions):
|
|||||||
subscriptions: A list of subscriptions for the CapDocument object.
|
subscriptions: A list of subscriptions for the CapDocument object.
|
||||||
Returns: A cleaned list of history bills.
|
Returns: A cleaned list of history bills.
|
||||||
"""
|
"""
|
||||||
|
# Get the BASEURL to generate absolute URLs
|
||||||
|
base_url = document.browser.BASEURL
|
||||||
try:
|
try:
|
||||||
assert subscriptions
|
assert subscriptions
|
||||||
history_bills = {
|
history_bills = {
|
||||||
@ -118,8 +127,38 @@ def fetch_history(document, subscriptions):
|
|||||||
return history_bills
|
return history_bills
|
||||||
|
|
||||||
|
|
||||||
|
def fetch(document, fetch_actions):
|
||||||
|
"""
|
||||||
|
Fetch all required items from a CapDocument object.
|
||||||
|
|
||||||
def to_cozy(document, actions={"fetch": True, "download": False}):
|
Args:
|
||||||
|
document: The CapDocument object to fetch from.
|
||||||
|
fetch_actions: A dict describing what should be fetched (see README.md)
|
||||||
|
Returns:
|
||||||
|
A tuple of fetched subscriptions, documents, bills, detailed bills and
|
||||||
|
history bills.
|
||||||
|
"""
|
||||||
|
subscriptions = fetch_subscriptions(document)
|
||||||
|
|
||||||
|
if fetch_actions is True or "documents" in fetch_actions:
|
||||||
|
documents, bills = fetch_documents(document, subscriptions)
|
||||||
|
else:
|
||||||
|
documents, bills = None, None
|
||||||
|
|
||||||
|
if fetch_actions is True or "detailed_bills" in fetch_actions:
|
||||||
|
detailed_bills = fetch_details(document, subscriptions)
|
||||||
|
else:
|
||||||
|
detailed_bills = None
|
||||||
|
|
||||||
|
if fetch_actions is True or "history_bills" in fetch_actions:
|
||||||
|
history_bills = fetch_history(document, subscriptions)
|
||||||
|
else:
|
||||||
|
history_bills = None
|
||||||
|
|
||||||
|
return (subscriptions, documents, bills, detailed_bills, history_bills)
|
||||||
|
|
||||||
|
|
||||||
|
def to_cozy(document, actions=None):
|
||||||
"""
|
"""
|
||||||
Export a CapDocument object to a JSON-serializable dict, to pass it to Cozy
|
Export a CapDocument object to a JSON-serializable dict, to pass it to Cozy
|
||||||
instance.
|
instance.
|
||||||
@ -129,26 +168,21 @@ def to_cozy(document, actions={"fetch": True, "download": False}):
|
|||||||
actions: A dict describing what should be fetched (see README.md).
|
actions: A dict describing what should be fetched (see README.md).
|
||||||
Returns: A JSON-serializable dict for the input object.
|
Returns: A JSON-serializable dict for the input object.
|
||||||
"""
|
"""
|
||||||
|
# Handle default parameters
|
||||||
|
if actions is None:
|
||||||
|
actions = {"fetch": True, "download": False}
|
||||||
|
|
||||||
# Get the BASEURL to generate absolute URLs
|
# Get the BASEURL to generate absolute URLs
|
||||||
base_url = document.browser.BASEURL
|
base_url = document.browser.BASEURL
|
||||||
|
|
||||||
|
# Handle fetch actions
|
||||||
if actions["fetch"] is True or "CapDocument" in actions["fetch"]:
|
if actions["fetch"] is True or "CapDocument" in actions["fetch"]:
|
||||||
subscriptions = fetch_subscriptions(document)
|
if actions["fetch"] is True:
|
||||||
|
fetch_actions = actions["fetch"]
|
||||||
if actions["fetch"] is True or "documents" in actions["fetch"]["CapDocument"]:
|
|
||||||
documents, bills = fetch_documents(document, subscriptions)
|
|
||||||
else:
|
else:
|
||||||
documents, bills = None, None
|
fetch_actions = actions["fetch"]["CapDocument"]
|
||||||
|
subscriptions, documents, bills, detailed_bills, history_bills = fetch(
|
||||||
if actions["fetch"] is True or "detailed_bills" in actions["fetch"]["CapDocument"]:
|
document, fetch_actions)
|
||||||
detailed_bills = fetch_details(document, subscriptions)
|
|
||||||
else:
|
|
||||||
detailed_bills = None
|
|
||||||
|
|
||||||
if actions["fetch"] is True or "history_bills" in actions["fetch"]["CapDocument"]:
|
|
||||||
history_bills = fetch_history(document, subscriptions)
|
|
||||||
else:
|
|
||||||
history_bills = None
|
|
||||||
|
|
||||||
# Return a formatted dict with all the infos
|
# Return a formatted dict with all the infos
|
||||||
return {
|
return {
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
from . import CapDocument
|
"""
|
||||||
|
Capabilities submodule
|
||||||
|
"""
|
||||||
|
from cozyweboob.capabilities import CapDocument
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"CapDocument"
|
"CapDocument"
|
||||||
|
@ -18,12 +18,12 @@ def clean_object(obj, base_url=None):
|
|||||||
# Convert object to a dict of its fields
|
# Convert object to a dict of its fields
|
||||||
obj = obj.to_dict()
|
obj = obj.to_dict()
|
||||||
# Clean the various fields to be JSON-serializable
|
# Clean the various fields to be JSON-serializable
|
||||||
for k, v in obj.items():
|
for key, value in obj.items():
|
||||||
if empty(v):
|
if empty(value):
|
||||||
# Replace empty values by None, avoid "NotLoaded is not
|
# Replace empty values by None, avoid "NotLoaded is not
|
||||||
# serializable" error
|
# serializable" error
|
||||||
obj[k] = None
|
obj[key] = None
|
||||||
elif k == "url" and base_url:
|
elif key == "url" and base_url:
|
||||||
# Render full absolute URLs
|
# Render full absolute URLs
|
||||||
obj[k] = base_url + v
|
obj[key] = base_url + value
|
||||||
return obj
|
return obj
|
||||||
|
@ -11,4 +11,7 @@ def is_in_debug_mode():
|
|||||||
Returns:
|
Returns:
|
||||||
true / false
|
true / false
|
||||||
"""
|
"""
|
||||||
return "COZYWEBOOB_ENV" in os.environ and os.environ["COZYWEBOOB_ENV"] == "debug"
|
return (
|
||||||
|
"COZYWEBOOB_ENV" in os.environ and
|
||||||
|
os.environ["COZYWEBOOB_ENV"] == "debug"
|
||||||
|
)
|
||||||
|
@ -20,4 +20,7 @@ class DummyProgress:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def prompt(self, message):
|
def prompt(self, message):
|
||||||
|
"""
|
||||||
|
Prompt function. Not implemented.
|
||||||
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
Loading…
Reference in New Issue
Block a user