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:
Jonas Wrede 2018-04-29 14:33:35 +02:00 committed by GitHub
parent 0a7823db7a
commit 6c61400565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -963,19 +963,27 @@ class SpeedtestResults(object):
writer.writerow([to_utf8(v) for v in row])
return out.getvalue()
def csv(self, delimiter=','):
"""Return data in CSV format"""
def byte_2_mbit(self, value):
return value/1000000
def csv(self, delimiter=',', mbit=False):
"""Return data in CSV format"""
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()
writer = csv.writer(out, delimiter=delimiter, lineterminator='')
row = [data['server']['id'], data['server']['sponsor'],
data['server']['name'], data['timestamp'],
data['server']['d'], data['ping'], data['download'],
data['upload'], self._share or '', self.client['ip']]
data['server']['d'], data['ping'], download,
upload, self._share or '', self.client['ip']]
writer.writerow([to_utf8(v) for v in row])
return out.getvalue()
def json(self, pretty=False):
"""Return data in JSON format"""