I'm trying to set up a script that automates internet speed tests (setting up a new network - so much testing!). It's straightforward using the Speedtest command line. The process runs in the background and gives a result.
How do I get Soundflow to interpret the output and show me only the variables I'm looking for?
We can assume the format/syntax of the output will always be the same, but with different number values. For example, it gives me the following result after running the process:
Retrieving speedtest.net configuration...
Testing from Virgin Media Ireland (109.255.241.176)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Three Ireland (Dublin) [1.07 km]: 15.46 ms
Testing download speed................................................................................
Download: 859.37 Mbit/s
Testing upload speed......................................................................................................
Upload: 49.08 Mbit/s
All I want to see is:
Download: 859
Upload: 49
- AAndrew Sherman @Andrew_Sherman
Ok I've partially answered my own question, you can simplify the result in the command line.
The command line process is:speedtest-cli --simple
Which gives:
Ping: 17.686 ms Download: 541.13 Mbit/s Upload: 22.49 Mbit/s
- In reply toAndrew_Sherman⬆:Christian Scheuer @chrscheuer2022-04-09 19:27:56.722Z
Try something like this:
let resultLines = sf.system.exec({ commandLine: `speedtest-cli` }).result.split(/\n/g).map(l => l.trim()); var downloadLine = resultLines.filter(l => l.startsWith("Download:"))[0]; var uploadLine = resultLines.filter(l => l.startsWith("Upload:"))[0]; var downloadSpeed = Number(downloadLine.split(':')[1].trim().split('Mbit')[0].trim()); var uploadSpeed = Number(uploadLine.split(':')[1].trim().split('Mbit')[0].trim()); log({ downloadSpeed, uploadSpeed, });
- AAndrew Sherman @Andrew_Sherman
Thanks very much Christian. Those Javascript tricks for working with text are so useful.