Python script to tweet your Internet speed

Published October 13, 2022

This is a simple Python script that tweets your Internet speed. I wrote this script because my former Internet provider C* suddenly slowed down and had very slow speeds of 1Mbps; my plan was supposedly up to 100Mbps download/10Mbps upload. This is a variant of what I originally wrote.

Tweet your Internet speed

To begin, you first need a Twitter account and have Python 3.8+ installed. You will also have to install pip.

Create Twitter application

First, create a Twitter application. Go to and click on Create New App.

After creating the application, click on the tab that says Keys and Access Tokens. Generate the Consumer Key and Secret. Also, generate the Access Token and Token Secret. Do not give these values to anyone.

Click on the tab Permissions and set the access to Read and Write.

Download speedtest cli program

Download the command line script from GitHub. Save it in a directory of your choice. I copied mine to /usr/local/bin/

Download my Python script

Copy my script to a directory of your choice. I copied mine to /usr/local/bin/

import subprocess
import tweepy
import requests

# Python script to tweet your Internet speed
# Arul John { }

def main():
  script_path = '/usr/local/bin/'
  # Find IP address and remove the last 2 octets
  ip = None
  r = requests.get('')
  if r.status_code ==
    ip = r.text
    if ip != None:
      ip =  '.'.join(ip.split('.')[:2]) + '.xx.xx'

  # Get the Internet speed by calling speedtest-cli
  speed = subprocess.check_output(['python', script_path, '--simple'])
  speed = "My #InternetSpeed :n" + speed
  if ip != None:
    speed += "IP address: " + ip

  # Twitter consumer key, secret, access token and secret
  consumer_key = ''
  consumer_secret = ''
  access_token = ''
  access_token_secret = ''
  auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  auth.set_access_token(access_token, access_token_secret)
  api = tweepy.API(auth)

  # Set status on Twitter
  status = api.update_status(status=speed)

  # Display information for logging

if __name__ == "__main__":

Edit and replace the four values (consumer_key, consumer_secret, access_token, access_token_secret) with the values in the Twitter application you just created. Also, replace the script_path value with the full path to the script.

Install Python modules requests and tweepy

You may or may not have the Python modules requests and tweepy. Let's install them.

pip install requests
pip install tweepy

Run the script

Now that the dependencies are installed, run the script:


Set as cronjob to run regularly

To set a cronjob to run this script and tweet your Internet speed every 3 hours, you can use this line:

# Run every 3 hours
5 0-23/3 * * * /usr/bin/python /usr/local/bin/ >> /tmp/speedtest.log

This is what your tweet will look like. You can modify the script accordingly to your style.

Please let me know if you run into any issues. Thanks for reading this post.

Related Posts

If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Last Updated: October 13, 2022.     This post was originally written on January 05, 2017.