Skip to content

Commit

Permalink
Merge pull request #40 from pjwarner/master
Browse files Browse the repository at this point in the history
Modified the response to not require the need to be gunzipped.  Looks …
  • Loading branch information
Janhouse committed Oct 23, 2017
2 parents eb3eb2c + 0cb3521 commit e9be003
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions tespeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,32 @@ def LoadServers(self):
sys.exit(1)

# Load etree from XML data
servers_xml = etree.fromstring(self.DecompressResponse(response))
servers_xml = etree.fromstring(response.read())
servers=servers_xml.find("servers").findall("server")
server_list=[]

for server in servers:
server_list.append({
'lat': float(server.attrib['lat']),
'lon': float(server.attrib['lon']),
'url': server.attrib['url'].rsplit('/', 1)[0] + '/',
#'url2': server.attrib['url2'].rsplit('/', 1)[0] + '/',
'name': server.attrib['name'],
'country': server.attrib['country'],
'sponsor': server.attrib['sponsor'],
'id': server.attrib['id'],
})
try:
server_list.append({
'lat': float(server.attrib['lat']),
'lon': float(server.attrib['lon']),
'url': server.attrib['url'][:-10],
'url2': server.attrib['url2'][:-10],
'name': server.attrib['name'],
'country': server.attrib['country'],
'sponsor': server.attrib['sponsor'],
'id': server.attrib['id'],
})
except:
server_list.append({
'lat': float(server.attrib['lat']),
'lon': float(server.attrib['lon']),
'url': server.attrib['url'][:-10],
'name': server.attrib['name'],
'country': server.attrib['country'],
'sponsor': server.attrib['sponsor'],
'id': server.attrib['id'],
})

return server_list

Expand All @@ -437,7 +448,6 @@ def DecompressResponse(sefl, response):
# Response isn't gzipped, therefore return the data.
return data.getvalue()


def FindBestServer(self):
print_debug("Looking for closest and best server...\n")
best=self.TestLatency(self.Closest([self.config['lat'], self.config['lon']], self.server_list, self.bestServers))
Expand Down

0 comments on commit e9be003

Please sign in to comment.