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 diff --git a/README.rst b/README.rst index fccf934..0202e4e 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. -------------------------------------------------------------------------- @@ -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 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 diff --git a/speedtest_cli.py b/speedtest_cli.py index d93d5c3..fddbd46 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='Append results to log file') + options = parser.parse_args() if isinstance(options, tuple): args = options[0] @@ -784,6 +787,33 @@ 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), + '%0.2f' % (ulspeed / 1000000 * 8), + config['client']['isp'], + config['client']['ip'], + best['sponsor'], + best['name'], + '%(d)0.2f, %(latency)0.2f' % 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) + + try: + log_file = open(args.log, 'a') + if fresh_file: + 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') + def main(): try: