From 20e5d12a5caa015653564c31f7845f1493148bed Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 16 Oct 2017 09:28:35 -0500 Subject: [PATCH] Support csv-delimiter for csv-header --- speedtest.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/speedtest.py b/speedtest.py index 8b8526a3c..cb4a374fe 100755 --- a/speedtest.py +++ b/speedtest.py @@ -36,7 +36,7 @@ gzip = None GZIP_BASE = object -__version__ = '1.0.6' +__version__ = '1.0.7' class FakeShutdownEvent(object): @@ -1212,11 +1212,15 @@ def version(): sys.exit(0) -def csv_header(): +def csv_header(delimiter=','): """Print the CSV Headers""" - print_('Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,' - 'Upload') + row = ['Server ID', 'Sponsor', 'Server Name', 'Timestamp', 'Distance', + 'Ping', 'Download', 'Upload'] + out = StringIO() + writer = csv.writer(out, delimiter=delimiter, lineterminator='') + writer.writerow([to_utf8(v) for v in row]) + print_(out.getvalue()) sys.exit(0) @@ -1349,12 +1353,12 @@ def shell(): raise SpeedtestCLIError('Cannot supply both --no-download and ' '--no-upload') - if args.csv_header: - csv_header() - if len(args.csv_delimiter) != 1: raise SpeedtestCLIError('--csv-delimiter must be a single character') + if args.csv_header: + csv_header(args.csv_delimiter) + validate_optional_args(args) socket.setdefaulttimeout(args.timeout)