Tweeting about your low internet speed and tagging your ISP

5 mins read ·
python imageprocessing

Sending tweet when your internet speed goes down
A lot of people liked the last post on and shared a lot of love on Reddit.

Some comments were really great and gave really actionable advice on what else we can do to improve it.

One of which was, Tweeting about your low internet speed and tagging your ISP.

This inspired me to quickly write this small Python code which can create an image with some text in it related to internet speed and tweet it tagging your ISP.😂

This is how the image looks.

Monitor your internet with python
Here is the tweet.

Install pillow and tweepy

Let’s see how can we achieve this.

pip install pillow
pip install tweepy
Read this post to know more about how to send tweets using tweepy.

Extend the code

import speedtest
import tweepy
from PIL import Image, ImageDraw, ImageFont
import datetime
s = speedtest.Speedtest()
import time

def create_image(downspeed, upspeed):
    img ='RGB', (1080, 750), color = (73, 109, 137))
    fnt = ImageFont.truetype('/Library/Fonts/Arial.ttf', 50)
    speed_string = f"Internet speed dropped \n Downspeed: {downspeed} \n Upspeed: {upspeed}"
    d = ImageDraw.Draw(img)
    d.text((300,325), speed_string, font=fnt, fill=(255, 255, 0))'pil_text_font.png')
    return speed_string

def tweet_image(downspeed, upspeed):
    speed_string = create_image(downspeed, upspeed)
    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)
    print('sending tweet')
    api.update_with_media('pil_text_font.png', status=speed_string)
    print('tweet sent')

while True:
    time_now ="%H:%M:%S")
    downspeed = round((round( / 1048576), 2)
    upspeed = round((round(s.upload()) / 1048576), 2)
    print(f"time: {time_now}, downspeed: {downspeed} Mb/s, upspeed: {upspeed} Mb/s")
    if downspeed < MIN_SPEED or upspeed < MIN_SPEED:
        tweet_image(downspeed, upspeed)
I have added two new functions to the old code where we were already computing the internet speed.

These functions do exactly what their name suggests.

create_image creates the image using pillow and tweet_image tweets an image using tweepy.

Code of create_image is taken from here.

You can configure the MIN_SPEED according to what your ISP( in MB/sec) promised when you brought the plan and add their Twitter handle in the speed_string to tag them.

Run the script

Run the script to send tweets directly to your Twitter handle whenever speed is below some limit.

Fun, right?

Hope you liked the post. Subscribe to the newsletter so that can get notifications of such posts.

One thing that I realized after writing this is what would happen if the internet is down. The tweet might not go and there might be an error raised by tweepy. It might be a good thing to test before using it live.

Please share your Feedback:

Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!