From: Fredrik Unger Date: Fri, 18 Jan 2013 10:49:13 +0000 (+0100) Subject: address.py: changed update check of address string X-Git-Url: https://source.tree.se/git?p=treecutter.git;a=commitdiff_plain;h=2631577aa8cdce4000f4b0240b701e38dca8d202;ds=sidebyside address.py: changed update check of address string If nominatim data does not exists (eg postcode is not there, but boundary or vice versa) then the old code failed with NoneType object. This addresses this but is not optimal. Current tests works with the sites, so using this solution for now. --- diff --git a/xinclude/address.py b/xinclude/address.py index 30e8a07..6a30d7a 100755 --- a/xinclude/address.py +++ b/xinclude/address.py @@ -135,7 +135,9 @@ def c(s): return s or '' def s(s,n): - return s or n + if n is not None: + return s or n.text + return s class Address(object): @@ -181,10 +183,11 @@ class Address(object): places = int(root.xpath('count(//place[@place_id])')) if places == 1: place = root.find("place") - self.postcode = s(self.postcode,place.find("boundary").text) - self.city = s(self.city,place.find("city").text) - self.country = s(self.country,place.find("country").text) - self.country_code = s(self.country_code,place.find("country_code").text) +# print etree.tostring(place,encoding='UTF-8',pretty_print=True) + self.postcode = s(self.postcode,place.find("postcode")) + self.city = s(self.city,place.find("city")) + self.country = s(self.country,place.find("country")) + self.country_code = s(self.country_code,place.find("country_code")) self.coord=Coord(place.get("lat"),place.get("lon")) return