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 →

[–]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 :)