Read JSON definitions of connectors to use on stdin

This commit is contained in:
Lucas Verney 2016-09-28 17:28:29 -04:00
parent 0abbf06225
commit 094696a0cd
4 changed files with 47 additions and 17 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.pyc
konnectors.json

1
TODO
View File

@ -1,2 +1,3 @@
* history (Detail) vs Bill?
* _url ?
* Update modules?

View File

@ -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
}
# 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 bill.to_cozy(connector.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)
)
)

7
konnectors.json.sample Normal file
View File

@ -0,0 +1,7 @@
{
"amazon": {
"website": "www.amazon.fr",
"email": "someone@example.com",
"password": "MY_AWESOME_PASSWORD"
}
}