This commit is contained in:
David Forbes 2016-07-16 09:56:11 +00:00 committed by GitHub
commit 7ed5eecae5
4 changed files with 38 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: