Created
September 22, 2021 03:02
-
-
Save michaelaye/67d3b9668b8667411eb83f77e83def8f to your computer and use it in GitHub Desktop.
Adding a timestring to speedtest csv output and add to csv file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from datetime import datetime as dt | |
from pathlib import Path | |
from sh import speedtest | |
fname = Path("multiple_connections_triton.csv") | |
now = dt.now() | |
def process_output(line): | |
"Remove the new line and append a time string" | |
out = line.rstrip("\n") + f',"{now.isoformat()}"\n' | |
with fname.open("a") as f: | |
f.write(out) | |
speedtest("--format=csv", _out=process_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment