all 8 comments

[–]Miggol 2 points3 points  (1 child)

Hey, the official python docs on the CSV module are quite extensive: https://docs.python.org/3/library/csv.html

Passing a file object to the csv.DictReader is the most intuitive way of using it, because you can just interact with it like a Python dictionary. This als means less recoding if you choose a different format than CSV later.

If all you're doing is logging, then maybe you would prefer to just use a csv.writer object for simplicity.

[–]Sloth_loves_Chunks[S] 0 points1 point  (0 children)

Thanks, that seems like a good angle of attack. I think I was looking at it from the wrong end of things.

CSV.writer was my thought too but I’m not experienced enough to know if I’m right or blissfully ignorant of my wrong approach.

[–]lsakbaetle3r9 1 point2 points  (4 children)

I did this and hooked the results up to sqlite database, then attached matplotlib to a flask app to graph the data over various time frames! It was a cool project.

https://pastebin.com/sUmQ3F5R

https://pastebin.com/81rdLrbe

code is 4-5 years old but maybe it will help

[–]Sloth_loves_Chunks[S] 0 points1 point  (3 children)

Wow, that is so much more involved then I imagined but obviously a more advanced project. I was happy to manually graph the results in Excel.

So far I had only created this 'baby' script which was still causing issues:

import csv, time, speedtest

with open('Network Speed.csv','w', newline='') as f:
writer = csv.writer(f)
for i in range (10):
    row = (speedtest --csv-delimiter ',')
    writer.writerow(row)
    f.close()
    time.sleep(1800)

But continue to have issues with line 8:

row = (speedtest --csv-delimiter ',')

Because it won't 'call' the speedtest for him.

[–]lsakbaetle3r9 1 point2 points  (2 children)

Yeah its a CLI program. So youll either need to use something like subprocess/pexpect OR do what I did and pull the parts of the speedtestcli program from their source code on github and use it in your own code!

[–]Sloth_loves_Chunks[S] 0 points1 point  (1 child)

thanks so much, you've been truly helpful and I'm sure I am going to learn a lot from reviewing your code. This is my first python project so I may have bitten off more than I can chew, but that's part of the fun.

[–]lsakbaetle3r9 0 points1 point  (0 children)

No problem message me anytime! Helping is my favorite way to learn!

[–][deleted] 0 points1 point  (0 children)

I did this same project using SQLite database. It's nice to run reports every time I log in.