From 099331018f1f42ad5d77473f7d3d6cc3527fdb67 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 21 Apr 2015 15:07:33 +0200 Subject: traffic: Fixed XML parsing and iteration. --- modules/traffic.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/traffic.py b/modules/traffic.py index a844b45..ad3c79c 100644 --- a/modules/traffic.py +++ b/modules/traffic.py @@ -7,7 +7,7 @@ info = { } import urllib2, urllib -from xml import etree +from xml.etree import ElementTree as ET counties = { 'Akershus': 2, @@ -78,11 +78,12 @@ class Module: url = 'http://www.vegvesen.no/trafikk/xml/search.xml?searchFocus.counties=%d' % counties[c] u = urllib2.urlopen(url) - xml = etree.parse(u) + xmldoc = ET.parse(u) + xml = xmldoc.getroot() results = [] - for message in xml.xpath('/searchresult/result-array/result/messages/message'): - if (rt and c and c.lower() in (x.text.lower() for x in message.xpath('actualCounties/string'))) or not c or not rt: + for message in xml.findall('result-array/result/messages/message'): + if (rt and c and c.lower() in (x.text.lower() for x in message.findall('actualCounties/string'))) or not c or not rt: if len(results) == 5: if rt and rn: results.append('More results: http://www.vegvesen.no/Trafikkinformasjon/Reiseinformasjon/Trafikkmeldinger?%s' % urllib.urlencode({ -- cgit v1.2.3