diff options
Diffstat (limited to 'net-analyzer/speedtest-cli/files/speedtest-cli-2.1.3-json-serverlist.patch')
-rw-r--r-- | net-analyzer/speedtest-cli/files/speedtest-cli-2.1.3-json-serverlist.patch | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/net-analyzer/speedtest-cli/files/speedtest-cli-2.1.3-json-serverlist.patch b/net-analyzer/speedtest-cli/files/speedtest-cli-2.1.3-json-serverlist.patch new file mode 100644 index 000000000000..455fd4bfd2eb --- /dev/null +++ b/net-analyzer/speedtest-cli/files/speedtest-cli-2.1.3-json-serverlist.patch @@ -0,0 +1,88 @@ +diff --git a/speedtest.py b/speedtest.py +index a33296d..e7490b1 100755 +--- a/speedtest.py ++++ b/speedtest.py +@@ -20,6 +20,7 @@ import re + import csv + import sys + import math ++import json + import errno + import signal + import socket +@@ -1250,10 +1251,7 @@ class Speedtest(object): + ) + + urls = [ +- '://www.speedtest.net/speedtest-servers-static.php', +- 'http://c.speedtest.net/speedtest-servers-static.php', +- '://www.speedtest.net/speedtest-servers.php', +- 'http://c.speedtest.net/speedtest-servers.php', ++ "://www.speedtest.net/api/js/servers", + ] + + headers = {} +@@ -1296,53 +1294,31 @@ class Speedtest(object): + printer('Servers XML:\n%s' % serversxml, debug=True) + + try: +- try: +- try: +- root = ET.fromstring(serversxml) +- except ET.ParseError: +- e = get_exception() +- raise SpeedtestServersError( +- 'Malformed speedtest.net server list: %s' % e +- ) +- elements = etree_iter(root, 'server') +- except AttributeError: +- try: +- root = DOM.parseString(serversxml) +- except ExpatError: +- e = get_exception() +- raise SpeedtestServersError( +- 'Malformed speedtest.net server list: %s' % e +- ) +- elements = root.getElementsByTagName('server') +- except (SyntaxError, xml.parsers.expat.ExpatError): ++ elements = json.loads(serversxml) ++ except SyntaxError: + raise ServersRetrievalError() + + for server in elements: +- try: +- attrib = server.attrib +- except AttributeError: +- attrib = dict(list(server.attributes.items())) +- +- if servers and int(attrib.get('id')) not in servers: ++ if servers and int(server.get('id')) not in servers: + continue + +- if (int(attrib.get('id')) in self.config['ignore_servers'] +- or int(attrib.get('id')) in exclude): ++ if (int(server.get('id')) in self.config['ignore_servers'] ++ or int(server.get('id')) in exclude): + continue + + try: + d = distance(self.lat_lon, +- (float(attrib.get('lat')), +- float(attrib.get('lon')))) ++ (float(server.get('lat')), ++ float(server.get('lon')))) + except Exception: + continue + +- attrib['d'] = d ++ server['d'] = d + + try: +- self.servers[d].append(attrib) ++ self.servers[d].append(server) + except KeyError: +- self.servers[d] = [attrib] ++ self.servers[d] = [server] + + break + |