Add CSV output option
--csv option will enable --simple and print result in CSV format. Useful if you want to eg. run periodic tests (eg. from cron) and log results for future analysis.
This commit is contained in:
parent
f1647f2c9e
commit
2b18cc806d
|
@ -460,6 +460,9 @@ def speedtest():
|
||||||
parser.add_argument('--simple', action='store_true',
|
parser.add_argument('--simple', action='store_true',
|
||||||
help='Suppress verbose output, only show basic '
|
help='Suppress verbose output, only show basic '
|
||||||
'information')
|
'information')
|
||||||
|
parser.add_argument('--csv', action='store_true',
|
||||||
|
help='Format results as CSV (ping, download, upload); '
|
||||||
|
'enables --simple as well')
|
||||||
parser.add_argument('--list', action='store_true',
|
parser.add_argument('--list', action='store_true',
|
||||||
help='Display a list of speedtest.net servers '
|
help='Display a list of speedtest.net servers '
|
||||||
'sorted by distance')
|
'sorted by distance')
|
||||||
|
@ -485,6 +488,10 @@ def speedtest():
|
||||||
source = args.source
|
source = args.source
|
||||||
socket.socket = bound_socket
|
socket.socket = bound_socket
|
||||||
|
|
||||||
|
# --csv enables --simple
|
||||||
|
if args.csv:
|
||||||
|
args.simple = True
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Retrieving speedtest.net configuration...')
|
print_('Retrieving speedtest.net configuration...')
|
||||||
try:
|
try:
|
||||||
|
@ -588,7 +595,10 @@ def speedtest():
|
||||||
print_('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
print_('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||||
'%(latency)s ms' % best)
|
'%(latency)s ms' % best)
|
||||||
else:
|
else:
|
||||||
print_('Ping: %(latency)s ms' % best)
|
if args.csv:
|
||||||
|
print_('%(latency)s,' % best, end='')
|
||||||
|
else:
|
||||||
|
print_('Ping: %(latency)s ms' % best)
|
||||||
|
|
||||||
sizes = [350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000]
|
sizes = [350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000]
|
||||||
urls = []
|
urls = []
|
||||||
|
@ -599,10 +609,14 @@ def speedtest():
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Testing download speed', end='')
|
print_('Testing download speed', end='')
|
||||||
dlspeed = downloadSpeed(urls, args.simple)
|
dlspeed = downloadSpeed(urls, args.simple)
|
||||||
if not args.simple:
|
|
||||||
print_()
|
if args.csv:
|
||||||
print_('Download: %0.2f M%s/s' %
|
print_('%0.2f,' % ((dlspeed / 1000 / 1000) * args.units[1]), end='')
|
||||||
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
else:
|
||||||
|
if not args.simple:
|
||||||
|
print_()
|
||||||
|
print_('Download: %0.2f M%s/s' %
|
||||||
|
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||||
|
|
||||||
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
|
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
|
||||||
sizes = []
|
sizes = []
|
||||||
|
@ -612,10 +626,14 @@ def speedtest():
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Testing upload speed', end='')
|
print_('Testing upload speed', end='')
|
||||||
ulspeed = uploadSpeed(best['url'], sizes, args.simple)
|
ulspeed = uploadSpeed(best['url'], sizes, args.simple)
|
||||||
if not args.simple:
|
|
||||||
print_()
|
if args.csv:
|
||||||
print_('Upload: %0.2f M%s/s' %
|
print_('%0.2f' % ((ulspeed / 1000 / 1000) * args.units[1]))
|
||||||
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
else:
|
||||||
|
if not args.simple:
|
||||||
|
print_()
|
||||||
|
print_('Upload: %0.2f M%s/s' %
|
||||||
|
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||||
|
|
||||||
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 '
|
||||||
|
|
Loading…
Reference in New Issue