HenrikBengtsson / speedtest-cli-extras

:signal_strength: Tools to enhance the speedtest-cli network tools
120 stars 32 forks source link

Support comma-separated output #1

Closed HenrikBengtsson closed 8 years ago

HenrikBengtsson commented 10 years ago

Currently it's not safe to use commas for separated values, because some servers return some values with commas rather than periods (probably due to their locale settings).

One solution would be to bluntly replace any commas with periods (in each of the fields/variables) before generating the one-line output, e.g. via sed.

Contributions appreciated.

HenrikBengtsson commented 10 years ago

I cannot recall exactly where/in what cases I got commas as part of the output, but I've seen it. Need an example output before this can be fixed.

andrew-stclair commented 8 years ago

if you use quotation marks like this it wont be an issue: "2016-04-02 19:14:04","2016-04-02 19:14:50","*","...","SoftLayer Technologies, Inc. (Melbourne)","12.18 km","38.572 ms","13.17 Mbit/s","0.84 Mbit/s","http://www.speedtest.net/result/****.png"

andrew-stclair commented 8 years ago

i made changes to my copy to fix this but i have not figured out github. its a very simple change anyway

andrew-stclair commented 8 years ago

I have a fork with the changes if you would like to take a look

HenrikBengtsson commented 8 years ago

Thanks for this. I've finally got around to do some updates that I wanted, which resulted in quite a few updates (all backward compatible for now):

% speedtest-csv --help
Usage:
 speedtest-csv [options]

Options:
 --debug        Output extra debug information
 --header       Display field names (only)
 --help         This help
 --last         Use most recent stats, iff available
 --quote <str>  Use <str> as quotation mark
 --sep <str>    Use <str> as field separator
 --standardize  Standardize units and number formats
 --version      Display version

Example:
 speedtest-csv --standardize --sep '\t'

Copyright: 2014-2016 Henrik Bengtsson
License: GPL (>= 2.1) [http://www.gnu.org/licenses/gpl.html]

With this, it is possible to use comma-separated tags and add quotation marks using:

$ speedtest-csv --standardize --sep ',' --quote '"'
"2016-04-03 20:11:02","2016-04-03 20:11:02","University of California - Office of the","169.230.x.x","Unwired (San Francisco, CA)","3.78 km","5.663 ms","743.21 Mbit/s","316.27 Mbit/s","http://www.speedtest.net/result/5222536160.png"

One can also output TAB-delimited output, e.g.

n14{henrik}: ./speedtest-csv --standardize --sep '\t' --last
2016-04-03 20:12:12     2016-04-03 20:12:12     University of California - Office of the        169.230.x.x Unwired (San Francisco, CA)      3.78 km 5.663 ms        743.21 Mbit/s   316.27 Mbit/s   http://www.speedtest.net/result/5222536160.png

Note how I use the new --last option, which skips querying the Speedtest server but instead using the most recent stats.