Add CSV saving functionality for speed test results #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request implements the functionality to save speed test results to a persistent CSV file (speedtest_history.csv).
(Why is this change necessary?)
Currently, the script is ephemeral. The results are displayed in the console, but are lost as soon as the execution ends.
This feature transforms the tool from a "one-time test" to a "monitoring tool," allowing users to do something they couldn't before: build a history of their internet performance, analyze connection patterns, and keep a record of the tests.
Changes Made->
New imports: Addition of the native csv and os and datetime libraries for file manipulation and timestamps. New Function: Creation of save_results_csv(data_row), which manages the logic for writing to the file. It checks if the speedtest_history.csv file already exists. If it doesn't exist, it creates the file and writes the headers. If it already exists, it simply appends the new results row. Modification to main(): At the end of the execution, the test data (Download, Upload, Ping, ISP, etc.) are collected in a dictionary and passed to the save_results_csv() function.
This is a "non-destructive" addition (non-breaking change) and does not alter any of the original functionalities, it only adds the saving step at the end.