rebase of pull request sivel/speedtest-cli/pull/162
This commit is contained in:
parent
7b09d8759f
commit
414f4d44ae
|
@ -74,9 +74,9 @@ Usage
|
||||||
::
|
::
|
||||||
|
|
||||||
$ speedtest-cli -h
|
$ speedtest-cli -h
|
||||||
usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list]
|
usage: speedtest_cli.py [-h] [--bytes] [--share] [--simple] [--list]
|
||||||
[--server SERVER] [--mini MINI] [--source SOURCE]
|
[--server SERVER] [--mini MINI] [--source SOURCE]
|
||||||
[--timeout TIMEOUT] [--secure] [--version]
|
[--timeout TIMEOUT] [--csv CSV] [--secure] [--version]
|
||||||
|
|
||||||
Command line interface for testing internet bandwidth using speedtest.net.
|
Command line interface for testing internet bandwidth using speedtest.net.
|
||||||
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
|
@ -95,6 +95,7 @@ Usage
|
||||||
--mini MINI URL of the Speedtest Mini server
|
--mini MINI URL of the Speedtest Mini server
|
||||||
--source SOURCE Source IP address to bind to
|
--source SOURCE Source IP address to bind to
|
||||||
--timeout TIMEOUT HTTP timeout in seconds. Default 10
|
--timeout TIMEOUT HTTP timeout in seconds. Default 10
|
||||||
|
--csv CSV Add data to file using csv format
|
||||||
--secure Use HTTPS instead of HTTP when communicating with
|
--secure Use HTTPS instead of HTTP when communicating with
|
||||||
speedtest.net operated servers
|
speedtest.net operated servers
|
||||||
--version Show the version number and exit
|
--version Show the version number and exit
|
||||||
|
|
|
@ -58,6 +58,11 @@ URL of the Speedtest Mini server
|
||||||
Source IP address to bind to
|
Source IP address to bind to
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
\fB\-\-csv\fR
|
||||||
|
.RS
|
||||||
|
CSV file to write to
|
||||||
|
.RE
|
||||||
|
|
||||||
\fB\-\-version\fR
|
\fB\-\-version\fR
|
||||||
.RS
|
.RS
|
||||||
Show the version number and exit
|
Show the version number and exit
|
||||||
|
|
|
@ -24,6 +24,8 @@ import socket
|
||||||
import timeit
|
import timeit
|
||||||
import platform
|
import platform
|
||||||
import threading
|
import threading
|
||||||
|
import csv
|
||||||
|
import datetime
|
||||||
|
|
||||||
__version__ = '0.3.4'
|
__version__ = '0.3.4'
|
||||||
|
|
||||||
|
@ -587,6 +589,7 @@ def speedtest():
|
||||||
parser.add_argument('--source', help='Source IP address to bind to')
|
parser.add_argument('--source', help='Source IP address to bind to')
|
||||||
parser.add_argument('--timeout', default=10, type=int,
|
parser.add_argument('--timeout', default=10, type=int,
|
||||||
help='HTTP timeout in seconds. Default 10')
|
help='HTTP timeout in seconds. Default 10')
|
||||||
|
parser.add_argument('--csv', help='Add data to file using csv format')
|
||||||
parser.add_argument('--secure', action='store_true',
|
parser.add_argument('--secure', action='store_true',
|
||||||
help='Use HTTPS instead of HTTP when communicating '
|
help='Use HTTPS instead of HTTP when communicating '
|
||||||
'with speedtest.net operated servers')
|
'with speedtest.net operated servers')
|
||||||
|
@ -735,6 +738,40 @@ def speedtest():
|
||||||
print_('Upload: %0.2f M%s/s' %
|
print_('Upload: %0.2f M%s/s' %
|
||||||
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||||
|
|
||||||
|
if args.csv:
|
||||||
|
filename = args.csv
|
||||||
|
file_exists = os.path.isfile(filename)
|
||||||
|
try:
|
||||||
|
csvfile = open(filename, 'ab+')
|
||||||
|
try:
|
||||||
|
|
||||||
|
headers = ['Test server', 'Date/Time', 'Latency (ms)',
|
||||||
|
'Dowload Speed (Kb/s)', 'Upload Speed (Kb/s)']
|
||||||
|
csvwriter = csv.DictWriter(csvfile, delimiter=';',
|
||||||
|
lineterminator='\n',
|
||||||
|
fieldnames=headers)
|
||||||
|
|
||||||
|
server = '%(sponsor)s (%(name)s) [%(d)0.2f km]' % best
|
||||||
|
current_time = datetime.datetime.now().strftime(
|
||||||
|
"%Y/%m/%d %H:%M:%S")
|
||||||
|
dlspeedk = int(round((dlspeed / 1000) * 8, 0))
|
||||||
|
ping = float(round(best['latency'], 2))
|
||||||
|
ulspeedk = int(round((ulspeed / 1000) * 8, 0))
|
||||||
|
|
||||||
|
if not file_exists:
|
||||||
|
csvwriter.writeheader()
|
||||||
|
|
||||||
|
csvwriter.writerow({'Test server': server,
|
||||||
|
'Date/Time': current_time,
|
||||||
|
'Latency (ms)': ping,
|
||||||
|
'Dowload Speed (Kb/s)': dlspeedk,
|
||||||
|
'Upload Speed (Kb/s)': ulspeedk})
|
||||||
|
finally:
|
||||||
|
csvfile.close()
|
||||||
|
except IOError:
|
||||||
|
print_("Unable to write CSV file")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if args.share and args.mini:
|
if args.share and args.mini:
|
||||||
print_('Cannot generate a speedtest.net share results image while '
|
print_('Cannot generate a speedtest.net share results image while '
|
||||||
'testing against a Speedtest Mini server')
|
'testing against a Speedtest Mini server')
|
||||||
|
|
Loading…
Reference in New Issue