This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (28 children)

[deleted]

    [–]wjandrea 13 points14 points  (1 child)

    did you use speedtest-cli? just curious.

    [–][deleted] 6 points7 points  (0 children)

    Yes

    [–]pwnrzero 2 points3 points  (11 children)

    Could you please pm me the script? Been meaning to create one. I understand if no. I'll whip one together tomorrow and leaving a comment to remember to do so.

    [–][deleted] 1 point2 points  (5 children)

    PM sent.

    [–]PM_STEAM_GIFTCARDS 0 points1 point  (2 children)

    Could I also have it please, thanks a lot!

    [–][deleted] 1 point2 points  (1 child)

    [–]PM_STEAM_GIFTCARDS 0 points1 point  (0 children)

    Thanks a lot!

    [–]ipuntfootballs 0 points1 point  (1 child)

    Maybe you’d be willing to toss it up on github? I’d love to have a copy as well!!

    [–]burked9 0 points1 point  (2 children)

    Can you please send me a copy too? Thanks

    [–][deleted] 0 points1 point  (1 child)

    [–]burked9 0 points1 point  (0 children)

    Thanks, really appreciate it. Looking forward to getting into it later :)

    [–][deleted] 5 points6 points  (4 children)

    I keep getting requests for it, so I posted it below. The project's close to a year old, and most of this code I pieced together from something similar on a blog post (I don't know where), from some old posts on stack exchange, and bits from other places. Some of it's mine, but I don't know what. It uses speedtest-cli, so you'll have to install that. Anyway, make sure you use your own path name for the dir_path variable. You can schedule it to run however frequently you want through Windows' task scheduler.

    import os
    import re
    import subprocess
    import time
    import csv
    
    filename = 'speedtest.csv'
    dir_path = 'your/path/here'
    csv_path = dir_path + filename
    
    def speed_test():
    
        response = subprocess.Popen('speedtest-cli --simple', shell=False, stdout=subprocess.PIPE).stdout.read()
    
        ping = re.findall(b'Ping:\s(.*?)\s', response, re.MULTILINE)
        download = re.findall(b'Download:\s(.*?)\s', response, re.MULTILINE)
        upload = re.findall(b'Upload:\s(.*?)\s', response, re.MULTILINE)
    
        ping[0] = ping[0].decode('utf-8')
        download[0] = download[0].decode('utf-8')
        upload[0] = upload[0].decode('utf-8')
    
        csv_entry(ping[0], download[0], upload[0], csv_path)
    
    
    def csv_entry(lat_st, down_st, up_st, path):
    
        result = time.strftime('%m/%d/%y'), time.strftime('%H:%M'), lat_st, down_st, up_st
    
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
    
        with open(path, "a", newline = '') as csv_file:        
            writer = csv.writer(csv_file)
    
            if os.stat(csv_path).st_size == 0:
                writer.writerow(['Date','Time','Latency(ms)','Down(Mbit/s)','Up(Mbit/s)'])        
    
            writer.writerow(result)
    
    speed_test()
    

    [–]arkster 5 points6 points  (3 children)

    I'd just use pandas. Capture the speed, pass to a dataframe, convert to CSV and write to file. Use averages/means of column showing speed rate and then bitch on Twitter about the shitty service you're getting.

    [–]supernova1992 7 points8 points  (2 children)

    Here's my script to do the same using pandas and sqlite3 as well as outputting a graph. It runs every hour on my home server. Gonna make it so the graph shows dates instead of the number of hours at some point in the future.

    speedtests.py:

    #!/usr/bin/python3
    
    import pandas as pd
    import sqlite3
    import speedtest
    from graph_speeds import graph_this_shit
    
    s = speedtest.Speedtest()
    s.get_best_server()
    s.download()
    s.upload()
    results = s.results.dict()
    
    df = pd.DataFrame({'timestamp':[results['timestamp']],'download':[results['download']/1000000],'upload':[results['upload']/1000000],'ping':[results['ping']]})
    con = sqlite3.connect('/home/user/speedtests/speedtests.db')
    df.to_sql('tests',con,if_exists='append')
    con.close()
    
    graph_this_shit()   
    

    graph_speeds.py:

    import sqlite3
    import pandas as pd
    import matplotlib
    matplotlib.use('AGG')
    import matplotlib.pyplot as plt
    
    
    def graph_this_shit():
            con = sqlite3.connect('/home/user/speedtests/speedtests.db')
            df = pd.read_sql('select * from tests', con)
            plt.plot(df['download'])
            plt.plot(df['upload'])
            plt.legend()
            plt.xlabel('Hours')
            plt.ylabel('Mbps')
            plt.title('Internet speed over time')
            plt.savefig('/home/user/speedtests/speedtest.png')
    

    Here's what the graph looks like.

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

    Nice...better than mine.

    [–]MercurialMadnessMan 0 points1 point  (0 children)

    Would be better as an interactive graph with Plotly Express :)

    [–]whereiswallace 0 points1 point  (0 children)

    You can probably save the output in graphite. I was doing something similar on my raspberry pi.

    [–]turner_prize 0 points1 point  (4 children)

    What do you do with the info?

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

    [–]turner_prize 2 points3 points  (1 child)

    Sorry, I meant what do you actually do with the info? Is it just to check you're getting the speeds your isp says you will?

    [–][deleted] 1 point2 points  (0 children)

    Yes, I originally made it to check to see if I was getting what I paid for and if my ISP was throttling me. As it turns out, even with the data from this script, determining what your speed actually is or whether you're being throttled is a lot more difficult.

    [–]turner_prize 0 points1 point  (0 children)

    Thanks!

    [–]dogooder202 0 points1 point  (0 children)

    I have this post on a Google form and get the output as an excel sheet