I'm using urllib2 and sre in Python to parse data from aprs.fi so I can use weather data in some real time high altitude balloon code I'm working on. The parsing code is pretty simple:
import urllib2
import sre
APRStracking = urllib2.urlopen( "http://api.aprs.fi/api/get?name=KD8REX&what=loc&apikey=42457.M4AFa3hdkXG31&format=xml" )
APRSxml = APRStracking.read()
latitude = sre.findall( '<la.*>(.*)</la.*>', APRSxml )
print latitude
The data I'm trying to parse is an XML, which looks like:
<xml>
<command>get</command>
<result>ok</result>
<what>loc</what>
<found>1</found>
<entries>
<entry>
<name>KD8REX</name>
<type>l</type>
<time>1339339410</time>
<lasttime>1339339410</lasttime>
<lat>41.95550</lat>
<lng>-83.65567</lng>
<altitude>2204.62</altitude>
<course>15</course>
<speed>15</speed>
<symbol>/O</symbol>
<srccall>KD8REX</srccall>
<dstcall>APT311</dstcall>
<status>UofM H.A.S. - Go Blue!</status>
<status_lasttime>1339339600</status_lasttime>
<path>WIDE1-1,WIDE3-3,qAR,W8SGZ</path>
</entry>
</entries>
</xml>
I'm not terribly familiar with Python, but my understanding of ser.findall() is that it looks through APRSxml looking for any strings that match the regular expression, and then appends whatever is between the parentheses in list "latitude." So, in this example, the two values that match the regular expression are "lasttime" and "lat." However, when I run this code it only outputs the <lat>
value, not <lasttime>
. Frankly, that's all I really need for my code to work, but out of curiosity, I'd appreciate if anyone could tell me why it isn't behaving as expected. Thanks.