diff --git a/.gitignore b/.gitignore index 0d20b64..060e5c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +konnectors.json diff --git a/TODO b/TODO index 68477a7..819ce0c 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,3 @@ * history (Detail) vs Bill? * _url ? +* Update modules? diff --git a/cozyweboob.py b/cozyweboob.py index 5544a60..01ac3ca 100755 --- a/cozyweboob.py +++ b/cozyweboob.py @@ -2,6 +2,8 @@ from __future__ import print_function import getpass +import json +import sys from weboob.core import Weboob @@ -9,7 +11,7 @@ from capabilities import bill from tools.jsonwriter import pretty_json -class Connector(object): +class WeboobProxy(object): """ Connector is a tool that connects to common websites like bank website, phone operator website... and that grabs personal data from there. @@ -20,10 +22,17 @@ class Connector(object): @staticmethod def version(): + """ + Return Weboob version. + """ return Weboob.VERSION - def update(self): - return self.weboob.update() + @staticmethod + def update(): + """ + Ensure modules are up to date. + """ + return Weboob().update() def __init__(self, modulename, parameters): """ @@ -45,29 +54,41 @@ class Connector(object): # Calls the backend. self.backend = self.weboob.build_backend(modulename, parameters) + def get_backend(self): + """ + Get the built backend. + """ + return self.backend -def main(email, password=None): + +def main(used_modules): """ Main code """ - if password is None: - # Ask for password if not provided - password = getpass.getpass("Password? ") + # Update all available modules + # TODO: WeboobProxy.update() - connector = Connector( - "amazon", - { - "website": "www.amazon.fr", - "email": email, - "password": password - } - ) - return bill.to_cozy(connector.backend) + # Fetch data for the specified modules + fetched_data = {} + for module, parameters in used_modules.items(): + # TODO + fetched_data["bills"] = bill.to_cozy( + WeboobProxy( + module, + parameters + ).get_backend() + ) + return fetched_data if __name__ == '__main__': + try: + konnectors = json.load(sys.stdin) + except ValueError: + sys.exit("Invalid input") # TODO + print( pretty_json( - main(raw_input("Email? ")) + main(konnectors) ) ) diff --git a/konnectors.json.sample b/konnectors.json.sample new file mode 100644 index 0000000..9973b33 --- /dev/null +++ b/konnectors.json.sample @@ -0,0 +1,7 @@ +{ + "amazon": { + "website": "www.amazon.fr", + "email": "someone@example.com", + "password": "MY_AWESOME_PASSWORD" + } +}