Read JSON definitions of connectors to use on stdin
This commit is contained in:
parent
0abbf06225
commit
094696a0cd
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
konnectors.json
|
||||||
|
1
TODO
1
TODO
@ -1,2 +1,3 @@
|
|||||||
* history (Detail) vs Bill?
|
* history (Detail) vs Bill?
|
||||||
* _url ?
|
* _url ?
|
||||||
|
* Update modules?
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
from weboob.core import Weboob
|
from weboob.core import Weboob
|
||||||
|
|
||||||
@ -9,7 +11,7 @@ from capabilities import bill
|
|||||||
from tools.jsonwriter import pretty_json
|
from tools.jsonwriter import pretty_json
|
||||||
|
|
||||||
|
|
||||||
class Connector(object):
|
class WeboobProxy(object):
|
||||||
"""
|
"""
|
||||||
Connector is a tool that connects to common websites like bank website,
|
Connector is a tool that connects to common websites like bank website,
|
||||||
phone operator website... and that grabs personal data from there.
|
phone operator website... and that grabs personal data from there.
|
||||||
@ -20,10 +22,17 @@ class Connector(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def version():
|
def version():
|
||||||
|
"""
|
||||||
|
Return Weboob version.
|
||||||
|
"""
|
||||||
return Weboob.VERSION
|
return Weboob.VERSION
|
||||||
|
|
||||||
def update(self):
|
@staticmethod
|
||||||
return self.weboob.update()
|
def update():
|
||||||
|
"""
|
||||||
|
Ensure modules are up to date.
|
||||||
|
"""
|
||||||
|
return Weboob().update()
|
||||||
|
|
||||||
def __init__(self, modulename, parameters):
|
def __init__(self, modulename, parameters):
|
||||||
"""
|
"""
|
||||||
@ -45,29 +54,41 @@ class Connector(object):
|
|||||||
# Calls the backend.
|
# Calls the backend.
|
||||||
self.backend = self.weboob.build_backend(modulename, parameters)
|
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
|
Main code
|
||||||
"""
|
"""
|
||||||
if password is None:
|
# Update all available modules
|
||||||
# Ask for password if not provided
|
# TODO: WeboobProxy.update()
|
||||||
password = getpass.getpass("Password? ")
|
|
||||||
|
|
||||||
connector = Connector(
|
# Fetch data for the specified modules
|
||||||
"amazon",
|
fetched_data = {}
|
||||||
{
|
for module, parameters in used_modules.items():
|
||||||
"website": "www.amazon.fr",
|
# TODO
|
||||||
"email": email,
|
fetched_data["bills"] = bill.to_cozy(
|
||||||
"password": password
|
WeboobProxy(
|
||||||
}
|
module,
|
||||||
)
|
parameters
|
||||||
return bill.to_cozy(connector.backend)
|
).get_backend()
|
||||||
|
)
|
||||||
|
return fetched_data
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
konnectors = json.load(sys.stdin)
|
||||||
|
except ValueError:
|
||||||
|
sys.exit("Invalid input") # TODO
|
||||||
|
|
||||||
print(
|
print(
|
||||||
pretty_json(
|
pretty_json(
|
||||||
main(raw_input("Email? "))
|
main(konnectors)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
7
konnectors.json.sample
Normal file
7
konnectors.json.sample
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"amazon": {
|
||||||
|
"website": "www.amazon.fr",
|
||||||
|
"email": "someone@example.com",
|
||||||
|
"password": "MY_AWESOME_PASSWORD"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user