Added mbit conversion in csv function
mbit conversion is pretty usefull to have in the right size when sending to another program.
This commit is contained in:
parent
0a7823db7a
commit
6c61400565
16
speedtest.py
16
speedtest.py
|
@ -963,19 +963,27 @@ class SpeedtestResults(object):
|
||||||
writer.writerow([to_utf8(v) for v in row])
|
writer.writerow([to_utf8(v) for v in row])
|
||||||
return out.getvalue()
|
return out.getvalue()
|
||||||
|
|
||||||
def csv(self, delimiter=','):
|
def byte_2_mbit(self, value):
|
||||||
"""Return data in CSV format"""
|
return value/1000000
|
||||||
|
|
||||||
|
def csv(self, delimiter=',', mbit=False):
|
||||||
|
"""Return data in CSV format"""
|
||||||
data = self.dict()
|
data = self.dict()
|
||||||
|
upload = data['upload']
|
||||||
|
download = data['download']
|
||||||
|
if mbit:
|
||||||
|
upload = self.byte_2_mbit(upload)
|
||||||
|
download = self.byte_2_mbit(download)
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
writer = csv.writer(out, delimiter=delimiter, lineterminator='')
|
writer = csv.writer(out, delimiter=delimiter, lineterminator='')
|
||||||
row = [data['server']['id'], data['server']['sponsor'],
|
row = [data['server']['id'], data['server']['sponsor'],
|
||||||
data['server']['name'], data['timestamp'],
|
data['server']['name'], data['timestamp'],
|
||||||
data['server']['d'], data['ping'], data['download'],
|
data['server']['d'], data['ping'], download,
|
||||||
data['upload'], self._share or '', self.client['ip']]
|
upload, self._share or '', self.client['ip']]
|
||||||
writer.writerow([to_utf8(v) for v in row])
|
writer.writerow([to_utf8(v) for v in row])
|
||||||
return out.getvalue()
|
return out.getvalue()
|
||||||
|
|
||||||
|
|
||||||
def json(self, pretty=False):
|
def json(self, pretty=False):
|
||||||
"""Return data in JSON format"""
|
"""Return data in JSON format"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue