Tweeting about your low internet speed and tagging your ISP
Monitor your internet with python
#python
#data-visualization
October 23, 2020
9 mins read
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.
Install pillow and tweepy
Let’s see how can we achieve this.pip install pillow
pip install tweepy
tweepy
.
How to create a webscraping twitter bot in Python
#python
#web-scraping
October 23, 2020
8 mins read
Extend the code
import speedtest
import tweepy
from PIL import Image, ImageDraw, ImageFont
import datetime
s = speedtest.Speedtest()
import time
MIN_SPEED = 100
def create_image(downspeed, upspeed):
img = Image.new('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))
img.save('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 = datetime.datetime.now().strftime("%H:%M:%S")
downspeed = round((round(s.download()) / 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)
time.sleep(10)
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
python monitor.py
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!