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',
|
||||
help='Suppress verbose output, only show basic '
|
||||
'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',
|
||||
help='Display a list of speedtest.net servers '
|
||||
'sorted by distance')
|
||||
|
@ -485,6 +488,10 @@ def speedtest():
|
|||
source = args.source
|
||||
socket.socket = bound_socket
|
||||
|
||||
# --csv enables --simple
|
||||
if args.csv:
|
||||
args.simple = True
|
||||
|
||||
if not args.simple:
|
||||
print_('Retrieving speedtest.net configuration...')
|
||||
try:
|
||||
|
@ -588,7 +595,10 @@ def speedtest():
|
|||
print_('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||
'%(latency)s ms' % best)
|
||||
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]
|
||||
urls = []
|
||||
|
@ -599,10 +609,14 @@ def speedtest():
|
|||
if not args.simple:
|
||||
print_('Testing download speed', end='')
|
||||
dlspeed = downloadSpeed(urls, args.simple)
|
||||
if not args.simple:
|
||||
print_()
|
||||
print_('Download: %0.2f M%s/s' %
|
||||
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||
|
||||
if args.csv:
|
||||
print_('%0.2f,' % ((dlspeed / 1000 / 1000) * args.units[1]), end='')
|
||||
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)]
|
||||
sizes = []
|
||||
|
@ -612,10 +626,14 @@ def speedtest():
|
|||
if not args.simple:
|
||||
print_('Testing upload speed', end='')
|
||||
ulspeed = uploadSpeed(best['url'], sizes, args.simple)
|
||||
if not args.simple:
|
||||
print_()
|
||||
print_('Upload: %0.2f M%s/s' %
|
||||
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||
|
||||
if args.csv:
|
||||
print_('%0.2f' % ((ulspeed / 1000 / 1000) * args.units[1]))
|
||||
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:
|
||||
print_('Cannot generate a speedtest.net share results image while '
|
||||
|
|
Loading…
Reference in New Issue