Skip to content

Instantly share code, notes, and snippets.

@michaelaye
Created September 22, 2021 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelaye/67d3b9668b8667411eb83f77e83def8f to your computer and use it in GitHub Desktop.
Save michaelaye/67d3b9668b8667411eb83f77e83def8f to your computer and use it in GitHub Desktop.
Adding a timestring to speedtest csv output and add to csv file.
#!/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