From 401e509ba9d568d202bc6765a5b1a830ede17c8b Mon Sep 17 00:00:00 2001 From: David Forbes Date: Tue, 12 Jul 2016 21:52:01 +0100 Subject: [PATCH 01/12] Simple log file capability added --- speedtest_cli.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/speedtest_cli.py b/speedtest_cli.py index d93d5c3..bd66084 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -24,6 +24,7 @@ import socket import timeit import platform import threading +import datetime __version__ = '0.3.4' @@ -593,6 +594,8 @@ def speedtest(): parser.add_argument('--version', action='store_true', help='Show the version number and exit') + parser.add_argument('--log', help='Specify a log file to append results to') + options = parser.parse_args() if isinstance(options, tuple): args = options[0] @@ -785,6 +788,26 @@ def speedtest(): (scheme, resultid[0])) + if args.log: + log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()), + '%0.2f'%(dlspeed /1000000 * 8), #Always megabits + '%0.2f'%(ulspeed /1000000 * 8), + config['client']['isp'], + config['client']['ip'], + '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best + ] + + if args.share: + log_output.append('%s://www.speedtest.net/result/%s.png' % (scheme, resultid[0])) + + fresh_file = not os.path.isfile(args.log) + + with open(args.log, "a") as log_file: + if fresh_file: + log_file.write("Date,download,upload,isp,ip,sponsor,location,distance,latency,share link") + log_file.write("%s\n" % ",".join(log_output)) + + def main(): try: speedtest() From 6849fb6b46ec013de348a7d18ba297288ebc9445 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Tue, 12 Jul 2016 22:04:34 +0100 Subject: [PATCH 02/12] Update README.rst --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index fccf934..c057d69 100644 --- a/README.rst +++ b/README.rst @@ -95,6 +95,7 @@ Usage --mini MINI URL of the Speedtest Mini server --source SOURCE Source IP address to bind to --timeout TIMEOUT HTTP timeout in seconds. Default 10 + --log LOGFILE Generate simple CSV logfile --secure Use HTTPS instead of HTTP when communicating with speedtest.net operated servers --version Show the version number and exit From 9fd6db48cf439d9353712bdf84cb7dcbee1c1989 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Tue, 12 Jul 2016 22:05:39 +0100 Subject: [PATCH 03/12] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c057d69..36d433e 100644 --- a/README.rst +++ b/README.rst @@ -76,7 +76,7 @@ Usage $ speedtest-cli -h usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list] [--server SERVER] [--mini MINI] [--source SOURCE] - [--timeout TIMEOUT] [--secure] [--version] + [--timeout TIMEOUT] [--log LOGFILE] [--secure] [--version] Command line interface for testing internet bandwidth using speedtest.net. -------------------------------------------------------------------------- From 74bfb2e17bd50767ded3be3e926ed07489b2ffea Mon Sep 17 00:00:00 2001 From: David Forbes Date: Tue, 12 Jul 2016 22:07:49 +0100 Subject: [PATCH 04/12] Update README.rst and man page --- README.rst | 2 +- speedtest-cli.1 | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 36d433e..0202e4e 100644 --- a/README.rst +++ b/README.rst @@ -95,7 +95,7 @@ Usage --mini MINI URL of the Speedtest Mini server --source SOURCE Source IP address to bind to --timeout TIMEOUT HTTP timeout in seconds. Default 10 - --log LOGFILE Generate simple CSV logfile + --log LOGFILE Append a one line CSV entry to LOGFILE --secure Use HTTPS instead of HTTP when communicating with speedtest.net operated servers --version Show the version number and exit diff --git a/speedtest-cli.1 b/speedtest-cli.1 index eb20ea7..3d4de55 100644 --- a/speedtest-cli.1 +++ b/speedtest-cli.1 @@ -58,6 +58,11 @@ URL of the Speedtest Mini server Source IP address to bind to .RE +\fB\-\-log LOGFILE\fR +.RS +File to append a CSV log entry to +.RE + \fB\-\-version\fR .RS Show the version number and exit From 274a53625de7e119b820e5ecc2ff8fc21e9c7b09 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Tue, 12 Jul 2016 23:50:33 +0100 Subject: [PATCH 05/12] Update to pass python 2.4 test --- speedtest_cli.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index bd66084..16c9241 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -594,7 +594,7 @@ def speedtest(): parser.add_argument('--version', action='store_true', help='Show the version number and exit') - parser.add_argument('--log', help='Specify a log file to append results to') + parser.add_argument('--log', help='Append results to log file') options = parser.parse_args() if isinstance(options, tuple): @@ -787,25 +787,28 @@ def speedtest(): print_('Share results: %s://www.speedtest.net/result/%s.png' % (scheme, resultid[0])) - if args.log: log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()), - '%0.2f'%(dlspeed /1000000 * 8), #Always megabits - '%0.2f'%(ulspeed /1000000 * 8), - config['client']['isp'], - config['client']['ip'], - '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best - ] + '%0.2f' % (dlspeed / 1000000 * 8), + '%0.2f' % (ulspeed / 1000000 * 8), + config['client']['isp'], + config['client']['ip'], + '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best + ] - if args.share: - log_output.append('%s://www.speedtest.net/result/%s.png' % (scheme, resultid[0])) + if args.share: + log_output.append('%s://www.speedtest.net/result/%s.png' % + (scheme, resultid[0])) - fresh_file = not os.path.isfile(args.log) + fresh_file = not os.path.isfile(args.log) - with open(args.log, "a") as log_file: - if fresh_file: - log_file.write("Date,download,upload,isp,ip,sponsor,location,distance,latency,share link") - log_file.write("%s\n" % ",".join(log_output)) + try: + log_file = open(args.log, "a") + if fresh_file: + log_file.write("Date,download,upload,isp,ip,spons,loc,dist,lat,share") + log_file.write("%s\n" % ",".join(log_output)) + except: + print_('\nLog file update failed') def main(): From 0e45b991f0242b9df9af6f01fc6b31c0f623ddc5 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Tue, 12 Jul 2016 23:52:29 +0100 Subject: [PATCH 06/12] Correction to add \n to the end of the header row --- speedtest_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index 16c9241..2f82f21 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -805,7 +805,7 @@ def speedtest(): try: log_file = open(args.log, "a") if fresh_file: - log_file.write("Date,download,upload,isp,ip,spons,loc,dist,lat,share") + log_file.write("Date,download,upload,isp,ip,spons,loc,dist,lat,share\n") log_file.write("%s\n" % ",".join(log_output)) except: print_('\nLog file update failed') From d9142d2b4e0ba1f560f075aa5f130fd58ecbe948 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Wed, 13 Jul 2016 00:03:48 +0100 Subject: [PATCH 07/12] Tidy up for flakes8 --- speedtest_cli.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index 2f82f21..e740d2b 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -788,18 +788,18 @@ def speedtest(): (scheme, resultid[0])) if args.log: - log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()), - '%0.2f' % (dlspeed / 1000000 * 8), - '%0.2f' % (ulspeed / 1000000 * 8), - config['client']['isp'], - config['client']['ip'], - '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best + log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()), + '%0.2f' % (dlspeed / 1000000 * 8), + '%0.2f' % (ulspeed / 1000000 * 8), + config['client']['isp'], + config['client']['ip'], + '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best ] if args.share: - log_output.append('%s://www.speedtest.net/result/%s.png' % + log_output.append('%s://www.speedtest.net/result/%s.png' % (scheme, resultid[0])) - + fresh_file = not os.path.isfile(args.log) try: From 02a735216e0ce323550d7cdb4290f9ef6d688989 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Wed, 13 Jul 2016 00:20:47 +0100 Subject: [PATCH 08/12] Tidy up visual indent --- speedtest_cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index e740d2b..5f6ef45 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -789,11 +789,11 @@ def speedtest(): if args.log: log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()), - '%0.2f' % (dlspeed / 1000000 * 8), - '%0.2f' % (ulspeed / 1000000 * 8), - config['client']['isp'], - config['client']['ip'], - '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best + '%0.2f' % (dlspeed / 1000000 * 8), + '%0.2f' % (ulspeed / 1000000 * 8), + config['client']['isp'], + config['client']['ip'], + '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best ] if args.share: From 1ef9e6a6f33884188c9885f19d7692b6c1795382 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Wed, 13 Jul 2016 00:23:22 +0100 Subject: [PATCH 09/12] Corrected quotes and line lengths --- speedtest_cli.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index 5f6ef45..8536857 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -803,10 +803,11 @@ def speedtest(): fresh_file = not os.path.isfile(args.log) try: - log_file = open(args.log, "a") + log_file = open(args.log, 'a') if fresh_file: - log_file.write("Date,download,upload,isp,ip,spons,loc,dist,lat,share\n") - log_file.write("%s\n" % ",".join(log_output)) + log_file.write('Date,download,upload,isp,ip,' + 'spons,loc,dist,lat,share\n') + log_file.write('%s\n' % ','.join(log_output)) except: print_('\nLog file update failed') From 33281a9606621a04f2777df56e45c4766238c844 Mon Sep 17 00:00:00 2001 From: David Forbes Date: Wed, 13 Jul 2016 00:31:49 +0100 Subject: [PATCH 10/12] Corrected line length --- speedtest_cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index 8536857..99f7e1a 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -793,8 +793,7 @@ def speedtest(): '%0.2f' % (ulspeed / 1000000 * 8), config['client']['isp'], config['client']['ip'], - '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s ms' % best - ] + '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s' % best] if args.share: log_output.append('%s://www.speedtest.net/result/%s.png' % From 8c4945c6c4c988b53dbd3baba7b1dd5517fac6cb Mon Sep 17 00:00:00 2001 From: David Forbes Date: Wed, 13 Jul 2016 22:05:12 +0100 Subject: [PATCH 11/12] Log file formatting tweaks --- speedtest_cli.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index 99f7e1a..fddbd46 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -788,12 +788,14 @@ def speedtest(): (scheme, resultid[0])) if args.log: - log_output = ['{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()), + log_output = ['{:%Y-%b-%d, %H:%M:%S}'.format(datetime.datetime.now()), '%0.2f' % (dlspeed / 1000000 * 8), '%0.2f' % (ulspeed / 1000000 * 8), config['client']['isp'], config['client']['ip'], - '%(sponsor)s,(%(name)s),%(d)0.2f km,%(latency)s' % best] + best['sponsor'], + best['name'], + '%(d)0.2f, %(latency)0.2f' % best] if args.share: log_output.append('%s://www.speedtest.net/result/%s.png' % @@ -804,9 +806,11 @@ def speedtest(): try: log_file = open(args.log, 'a') if fresh_file: - log_file.write('Date,download,upload,isp,ip,' - 'spons,loc,dist,lat,share\n') - log_file.write('%s\n' % ','.join(log_output)) + log_file.write('Date, Time, Download (Mbps), Upload (Mbps), ' + 'Your ISP, Your IP, ' + 'Sponsor, Location, Distance (km), ' + 'Latency (ms), Sharing link\n') + log_file.write('%s\n' % ', '.join(log_output)) except: print_('\nLog file update failed') From aed0cb57f20db3c07971a344cfcf52c4fe86f82e Mon Sep 17 00:00:00 2001 From: David Forbes Date: Sat, 16 Jul 2016 10:56:05 +0100 Subject: [PATCH 12/12] Remove python 3.2 testing as no longer supported by testing suite --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e8b3a20..b15b5ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: - TOXENV=py25 - TOXENV=py26 - TOXENV=py27 - - TOXENV=py32 +# - TOXENV=py32 # Testing suite reports python 3.2 not supported - TOXENV=py33 - TOXENV=py34 - TOXENV=pypy