update with new save to csv
This commit is contained in:
parent
90731dab5d
commit
8d63cf52e4
|
|
@ -25,6 +25,16 @@
|
|||
// }
|
||||
// "cwd": "${workspaceFolder}",
|
||||
"justMyCode": false
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Python: list",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/speedtest.py",
|
||||
"console": "integratedTerminal",
|
||||
"args": ["--list"],
|
||||
"justMyCode": false
|
||||
}
|
||||
]
|
||||
}
|
||||
1
setup.py
1
setup.py
|
|
@ -95,5 +95,6 @@ setup(
|
|||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.9',
|
||||
'Programming Language :: Python :: 3.10',
|
||||
'Programming Language :: Python :: 3.11',
|
||||
]
|
||||
)
|
||||
|
|
|
|||
58
speedtest.py
58
speedtest.py
|
|
@ -1943,40 +1943,36 @@ def shell():
|
|||
speedtest.get_best_server(speedtest.set_mini_server(args.mini))
|
||||
|
||||
results = speedtest.results
|
||||
# print(dict(str(results)))
|
||||
# os.makedirs('tmp', exist_ok=True)
|
||||
# utilities.convert_and_save_to_xlsx(str(results), "tmp/output.xlsx")
|
||||
# utilities.convert_and_save_to_csv(str(results), "tmp/data.csv")
|
||||
|
||||
printer('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||
'%(latency)s ms' % results.server, quiet)
|
||||
# printer('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||
# '%(latency)s ms' % results.server, quiet)
|
||||
|
||||
if args.download:
|
||||
printer('Testing download speed', quiet,
|
||||
end=('', '\n')[bool(debug)])
|
||||
# printer('Testing download speed', quiet,
|
||||
# end=('', '\n')[bool(debug)])
|
||||
speedtest.download(
|
||||
callback=callback,
|
||||
threads=(None, 1)[args.single]
|
||||
)
|
||||
printer('Download: %0.2f M%s/s' %
|
||||
((results.download / 1000.0 / 1000.0) / args.units[1],
|
||||
args.units[0]),
|
||||
quiet)
|
||||
# printer('Download: %0.2f M%s/s' %
|
||||
# ((results.download / 1000.0 / 1000.0) / args.units[1],
|
||||
# args.units[0]),
|
||||
# quiet)
|
||||
else:
|
||||
printer('Skipping download test', quiet)
|
||||
|
||||
if args.upload:
|
||||
printer('Testing upload speed', quiet,
|
||||
end=('', '\n')[bool(debug)])
|
||||
# printer('Testing upload speed', quiet,
|
||||
# end=('', '\n')[bool(debug)])
|
||||
speedtest.upload(
|
||||
callback=callback,
|
||||
pre_allocate=args.pre_allocate,
|
||||
threads=(None, 1)[args.single]
|
||||
)
|
||||
printer('Upload: %0.2f M%s/s' %
|
||||
((results.upload / 1000.0 / 1000.0) / args.units[1],
|
||||
args.units[0]),
|
||||
quiet)
|
||||
# printer('Upload: %0.2f M%s/s' %
|
||||
# ((results.upload / 1000.0 / 1000.0) / args.units[1],
|
||||
# args.units[0]),
|
||||
# quiet)
|
||||
else:
|
||||
printer('Skipping upload test', quiet)
|
||||
|
||||
|
|
@ -2004,18 +2000,20 @@ def shell():
|
|||
|
||||
|
||||
def main():
|
||||
try:
|
||||
shell()
|
||||
except KeyboardInterrupt:
|
||||
printer('\nCancelling...', error=True)
|
||||
except (SpeedtestException, SystemExit):
|
||||
e = get_exception()
|
||||
# Ignore a successful exit, or argparse exit
|
||||
if getattr(e, 'code', 1) not in (0, 2):
|
||||
msg = '%s' % e
|
||||
if not msg:
|
||||
msg = '%r' % e
|
||||
raise SystemExit('ERROR: %s' % msg)
|
||||
for i in range(0,3):
|
||||
try:
|
||||
shell()
|
||||
except KeyboardInterrupt:
|
||||
printer('\nCancelling...', error=True)
|
||||
except (SpeedtestException, SystemExit):
|
||||
e = get_exception()
|
||||
# Ignore a successful exit, or argparse exit
|
||||
if getattr(e, 'code', 1) not in (0, 2):
|
||||
msg = '%s' % e
|
||||
if not msg:
|
||||
msg = '%r' % e
|
||||
raise SystemExit('ERROR: %s' % msg)
|
||||
i+=1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
12
utilities.py
12
utilities.py
|
|
@ -65,15 +65,3 @@ def flatten_dict(d, parent_key='', sep='_'):
|
|||
else:
|
||||
items.append((new_key, v))
|
||||
return dict(items)
|
||||
|
||||
# Sample input string
|
||||
sample_input = "{'download': 0, 'upload': 0, 'ping': 9.319, 'server': {'url': 'http://speedtest.nextgentel.no:8080/speedtest/upload.php', 'lat': '59.9494', 'lon': '10.7564', 'name': 'Oslo', 'country': 'Norway', 'cc': 'NO', 'sponsor': 'NextGenTel AS', 'id': '8018', 'host': 'speedtest.nextgentel.no:8080', 'd': 5.7463776547060155, 'latency': 9.319}, 'timestamp': '2024-01-01T20:06:56.839888Z', 'bytes_sent': 0, 'bytes_received': 0, 'share': None, 'client': {'ip': '84.215.59.36', 'lat': '59.955', 'lon': '10.859', 'isp': 'Telia Norge AS', 'isprating': '3.7', 'rating': '0', 'ispdlavg': '0', 'ispulavg': '0', 'loggedin': '0', 'country': 'NO'}}"
|
||||
|
||||
# Specify the file name
|
||||
file_name = "output.xlsx"
|
||||
|
||||
# Call the function with the sample input and file name
|
||||
convert_and_save_to_xlsx(sample_input, file_name)
|
||||
|
||||
|
||||
# py .\speedtest.py --csv
|
||||
Loading…
Reference in New Issue