diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2015-04-21 15:07:33 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2015-04-21 15:07:33 +0200 |
commit | 099331018f1f42ad5d77473f7d3d6cc3527fdb67 (patch) | |
tree | 665641c871ddd29176202ab33130ececd9692726 | |
parent | 287f229ad4d368f16a60d708d7a07eb9a8bcad69 (diff) |
traffic: Fixed XML parsing and iteration.
-rw-r--r-- | modules/traffic.py | 9 |
1 files 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({ |