Quantcast
Channel: Matt Huisman
Viewing all articles
Browse latest Browse all 191

Python ISP Speed Twitter Bot

$
0
0
Here is how to build a simple Python script to Tweet your ISP when your internet speed is less than what you are paying for.

Just like THIS GUY did.

I have tested this working with Python2.7.

You will need a 2x Python libraries installed.

Simply use pip to install them

pip install speedtest_cli
pip install twython

Once they are installed, download my scriptHERE.
Save it as main.py anywhere you like.

Open the file in your favorite text editor or IDE.

The first thing you can set is SERVERS which is a list of speedtest.net server ID's to test against.
To find the server ID's, visit http://www.speedtest.net/speedtest-servers.php


The defaults ids are SERVERS = [922,4934] which are 2degrees & Vodafone Christchurch NZ servers.
If you have a list, it will test each and then calculate the average download and upload speed.
You can just have 1x server in the list if you just want to use a single server. eg SERVERS = [922]

You can also set SERVERS = None
If you set this, then the script will find the closest server with the best ping and use that.
No averages therefore need calculating.

Next you can put in your ISP's download and upload speeds that you are paying for.
These are in megabits per second which is most common way they are advertised.

You then set the percentage threshold. If your download or upload speed is less than X percent of the ISP's speeds then it will send the Tweet.
Default is TWEET_THRESHHOLD = 80 (any speed less than 80 percent will cause tweet)

You then have DELAY. The script has been setup to run once and keep running every X seconds.
Default is DELAY = 60*60*24 (= 24 hours)

You can then set the tweet to send. Make sure you have  4 lots of the placeholders %0.0f or it will cause an error when it replaces those with your actual speeds.
The default is
TWEET = "Hey @bigisp why is my internet speed %0.0fdown\%0.0fup when I pay for %0.0fdown\%0.0fup in Christchurch, NZ? #bigisp #speedtest"


The script will now upload an image of the speed test results with your tweet.
If you don't want the image, set POST_IMAGE = False.

Finally you have the 4x twitter variables that you need to set.

First, login to your twitter.
Now go to http://apps.twitter.com/ and create a new app



Now fill in the required fields.


(If you get an error about phone number, you need to go to your twitter settings and register your phone)

Once the app is created, go to the "Keys and Access Tokens" tab and click "Create my access token"


 Now copy the four fields into the script/


Save the script and it's now ready to go!

Simply run the script using python main.py and watch it check your speeds and then tweet if required!

Note: This was just a quick script I wrote to test it out - there is little error checking etc.

Viewing all articles
Browse latest Browse all 191

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>