Skip to content

Commit

Permalink
Support csv-delimiter for csv-header
Browse files Browse the repository at this point in the history
  • Loading branch information
sivel committed Oct 16, 2017
1 parent 6603954 commit 20e5d12
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
gzip = None
GZIP_BASE = object

__version__ = '1.0.6'
__version__ = '1.0.7'


class FakeShutdownEvent(object):
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 20e5d12

Please sign in to comment.