From 8d63cf52e4a0f072656a218cdc04a82a8d548ffa Mon Sep 17 00:00:00 2001 From: kuzh Date: Sun, 11 Feb 2024 16:52:44 +0100 Subject: [PATCH] update with new save to csv --- .vscode/launch.json | 10 ++++++++ setup.py | 1 + speedtest.py | 58 ++++++++++++++++++++++----------------------- utilities.py | 12 ---------- 4 files changed, 39 insertions(+), 42 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 96bdd41..2840abc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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 } ] } \ No newline at end of file diff --git a/setup.py b/setup.py index f3d21ad..4716a81 100644 --- a/setup.py +++ b/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', ] ) diff --git a/speedtest.py b/speedtest.py index 7d8dc07..1f00f8a 100755 --- a/speedtest.py +++ b/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__': diff --git a/utilities.py b/utilities.py index 5def226..b7b38ad 100644 --- a/utilities.py +++ b/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 \ No newline at end of file