Implement Details in CapDocument

This commit is contained in:
Lucas Verney 2016-09-29 17:28:39 -04:00
parent d8cf10bfa9
commit 697edaefa3
2 changed files with 32 additions and 10 deletions

3
TODO
View File

@ -1,5 +1,4 @@
* history (Detail) vs Bill?
* Bill._url?
* Bills vs Details?
* Update modules?
* amazon.com is buggy

View File

@ -6,16 +6,39 @@ def to_cozy(document):
Export a CapDocument object to JSON, to pass it to Cozy instance.
"""
# Fetch the list of subscriptions
try:
subscriptions = list(document.iter_subscription())
# Return a formatted dict with all the infos
return {
"subscriptions": [ # List of subscriptions
clean_object(subscription) for subscription in subscriptions
],
"bills": { # List of bills for each subscription
except NotImplementedError:
subscriptions = None
# Fetch and clean the list of bills
try:
assert(subscriptions)
bills = {
subscription.id: [
clean_object(bill) for bill in document.iter_bills(subscription)
clean_object(bill) for bill in document.iter_documents(subscription)
]
for subscription in subscriptions
}
except (NotImplementedError, AssertionError):
bills = None
# Fetch and clean the list of history bills (detailed consumption)
try:
assert(subscriptions)
detailed_bills = {
subscription.id: [
clean_object(detailed_bill)
for detailed_bill in document.get_details(subscription)
]
for subscription in subscriptions
}
except (NotImplementedError, AssertionError):
detailed_bills = None
# Return a formatted dict with all the infos
ret = {
"subscriptions": [ # Clean the subscriptions list
clean_object(subscription) for subscription in subscriptions
],
"bills": bills,
"detailed_bills": detailed_bills
}
return ret