Solved Python 2.4 build compatibilty and flake8 warnings
This commit is contained in:
parent
bd4bced399
commit
cdf2724bd8
|
@ -739,31 +739,31 @@ def speedtest():
|
||||||
if args.csv:
|
if args.csv:
|
||||||
filename = args.csv
|
filename = args.csv
|
||||||
file_exists = os.path.isfile(filename)
|
file_exists = os.path.isfile(filename)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(filename, 'ab+') as csvfile:
|
csvfile = open(filename, 'ab+')
|
||||||
|
try:
|
||||||
|
|
||||||
headers = ['Test server', 'Date/Time', 'Latency (ms)',
|
headers = ['Test server', 'Date/Time', 'Latency (ms)',
|
||||||
'Dowload Speed (Kb/s)', 'Upload Speed (Kb/s)']
|
'Dowload Speed (Kb/s)', 'Upload Speed (Kb/s)']
|
||||||
csvwriter = csv.DictWriter(csvfile, delimiter=';',
|
csvwriter = csv.DictWriter(csvfile, delimiter=';',
|
||||||
lineterminator='\n',fieldnames=headers)
|
lineterminator='\n',
|
||||||
|
fieldnames=headers)
|
||||||
|
|
||||||
server = '%(sponsor)s (%(name)s) [%(d)0.2f km]' % best
|
server = '%(sponsor)s (%(name)s) [%(d)0.2f km]' % best
|
||||||
current_time = datetime.datetime.now().isoformat()
|
current_time = datetime.datetime.now().isoformat()
|
||||||
dlspeedk = int(round((dlspeed / 1000) * 8, 0))
|
dlspeedk = int(round((dlspeed / 1000) * 8, 0))
|
||||||
ping = float(round(best['latency'], 2))
|
ping = float(round(best['latency'], 2))
|
||||||
ulspeedk = int(round((ulspeed / 1000) * 8, 0))
|
ulspeedk = int(round((ulspeed / 1000) * 8, 0))
|
||||||
|
|
||||||
|
if not file_exists:
|
||||||
|
csvwriter.writeheader()
|
||||||
|
|
||||||
if not file_exists:
|
csvwriter.writerow({'Test server': server,
|
||||||
csvwriter.writeheader()
|
'Date/Time': current_time,
|
||||||
|
'Latency (ms)': ping,
|
||||||
csvwriter.writerow({'Test server': server,
|
'Dowload Speed (Kb/s)': dlspeedk,
|
||||||
'Date/Time': current_time,
|
'Upload Speed (Kb/s)': ulspeedk})
|
||||||
'Latency (ms)': ping,
|
finally:
|
||||||
'Dowload Speed (Kb/s)': dlspeedk,
|
|
||||||
'Upload Speed (Kb/s)': ulspeedk
|
|
||||||
})
|
|
||||||
csvfile.close()
|
csvfile.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
print_("Unable to write CSV file")
|
print_("Unable to write CSV file")
|
||||||
|
|
Loading…
Reference in New Issue