From 716e127e1a46974c58139f3ab6bff9ed92196a00 Mon Sep 17 00:00:00 2001 From: christopherlam Date: Sun, 5 Feb 2017 14:58:04 +0800 Subject: Bugfix pricedb may not exist --- gnucashxml.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gnucashxml.py b/gnucashxml.py index 76ba930..95e99ab 100644 --- a/gnucashxml.py +++ b/gnucashxml.py @@ -238,7 +238,14 @@ class Price(object): self.value, self.currency) - + def __lt__(self, other): + # For sorted() only + if isinstance(other, Price): + return self.date < other.date + else: + False + + ################################################################## # XML file parsing @@ -291,9 +298,10 @@ def _book_from_tree(tree): prices = [] t = tree.find('{http://www.gnucash.org/XML/gnc}pricedb') - for child in t.findall('price'): - price = _price_from_tree(child, commoditydict) - prices.append(price) + if t: + for child in t.findall('price'): + price = _price_from_tree(child, commoditydict) + prices.append(price) root_account = None accounts = [] -- cgit v1.2.3