Find your machine learning mojo!

How To Use Web Bots And Begin Automating Boring Tasks

With time being very much of the essence for millennials and the constant pressure to be seen as delivering value, there is a need for automation. A web bot, or just bot for short, is a piece of software used to automate repetitive tasks online.

Since the dawn of humanity, people have sought to make their lives easy through the use of machines, and more recently robots.

It will come as no surprise then, that with the invention of the web, people created web bots to automate simple tasks.

I believe it was Einstein who said, and I’m paraphrasing, ‘Why would I bother to remember the information I can access easily?’

Why indeed?

I like to take that one step further,

Why bother to complete a manual task that I can automate easily?

I am incredibly lazy by nature which hates spending time on repetitive actions.

I love to automate anything I can so that I don’t have to think about it. It gives me so much more time for naps!

Having completed my programming nanodegree, and inspired by Automate the Boring Stuff, the book I used to help me learn Python, I decided to try my hand at creating a web bot to automate some of my Twitter accounts.

Ready to get started with Machine Learning Algorithms? Try the FREE Bootcamp

What is a web bot?

So what is a web bot? As I mentioned earlier, a web bot is a piece of software that is used to automate tasks online.

One example of a web bot in action is a crawler bot. What this crawler bot does is it scans a webpage or files on a server and reports back what it finds. This type of crawler web bot is used by companies like Google to determine which web pages to surface in the search results.

Three other examples of different types of web bots are:

  • Commercial bots: Commercial bots are used by people to make quick trades and scan for deals on sites such as eBay.
  • Malicious bots: Malicious bots can be used to spread malware that will download a person’s password information and financial details.
  • Social bots: These can come in the form of chatbots that will interest people or bots like those used to mimic human behaviors on social media.

The three examples listed above don’t sound too good for humanity. There have definitely been plenty of examples of people miss-using the technology in recent times. As one example, some of the viral nature of the spread of fake news can undoubtedly be linked back to bots.

So why would any moral person want to create a web bot?

Why would you want to create a web bot?

Despite specific web bots having negative outputs, there are still many reasons why you may wish to create one.

Bots are typically created as they are able to complete tasks much faster than a human can.

Also, bots don’t get bored.

Here are three reasons someone would create a bot:

  • Cost savings – the automation of manual tasks does save money. Running a simple bot is a relatively inexpensive process when compared to hiring a person. Sure you may need to have a programmer build it for you, but once it’s done your good to go.
  • Time-saving – automating tasks saves you time. It gives you more opportunity to work on high value-adding activities – or naps!
  • Laziness – this is not most people’s reason for wanting to create a bot, but it is mine. I’m just lazy and cannot be bothered to do the things my bot can do for me.

‘What, ‘ I hear you ask, ‘are you too lazy to do Claire?’

Well, my friend, I am too lazy to crawl through the endless stream of content on Twitter to find and share articles I am interested in. So I am going to create a Twitter bot using Python.

creating a Twitter bot

Creating a Twitter bot that automatically re-tweets and follows users

Creating a Twitter web bot that will automatically re-tweet and follow users will be of great use to me.

I have, as I am sure you can relate to, very little time spare to spend crawling Twitter. However, I know there is loads of great content being shared on there every day.
To take advantage of this, and not get FOMO, I am going to use the Twitter bot to scan for tweets I might like, retweet them so my followers and I can see them, then follow the original tweeter.

This last step of following the user is to be able to see any exciting content they put out in the future.

One thing I don’t want to do however is get overwhelmed with content. I also don’t want to spam or overwhelm others, so I am going to set my bot up to only tweet 3 times per day.

Having decided what I want to achieve now, it’s time to move on to creating a Twitter bot.

My experience creating a Twitter Bot

This may come as somewhat of a surprise to those of you who have been with me through my programming journey but, creating a Twitter bot is pretty easy.

I was able to use one of the skills I developed during my programming nanodegree, googling. I was able to quickly find a couple of online tutorials for creating a Twitter bot.

In total it took me about an hour and a half to code, edit and test out my Twitter bot – who I have nick-named Mrs. Tweets.

These are the tutorials I used to create a Twitter bot:

  • Free code camp, on Medium: This article is where I took the majority of my starter code from. It allowed me to create the framework for my Twitter bot. I used everything up to the tweet a phrase section. I excluded the phrase section as this was not something I wanted my Twitter bot to do.
  • Creating a Twitter bot, on Digital Ocean: This article was a bit more in depth. I used the content here to add in some of the functionality, such as following the user after my bot, Mrs. Tweets, retweeted their post. I also used this to understand where I should add in the limits on how often to tweet as this wasn’t covered in the Medium post.

Twitter GIF - Find & Share on GIPHY

Testing and automating a Twitter Bot

Once I had tested my Twitter bot and saw that Mrs. Tweets was performing as I wanted her to, it was time to automate. I used the article from digitalOcean, linked above to set her up top run automatically. It works even when my computer is off.

This was the most challenging part.

I had to remember everything from my course on how to check and change the directory I was running my program in.

Once I had all the required files and libraries running from the right directory, it was pretty straightforward. Everything you need is in the digitalOcean tutorial.

Now it’s completed I’m excited to say that I created a Twitter bot!

I recommend anyone who is learning Python to have a go at creating a bot. Not only is it great to get practice using more libraries, but the script you end up running is visual.

You can see it taking action, just like those Javascript and front-end developers get to all the time!

Let’s take a look at some web bot code in python

Below you can see the code I wrote for a Twitter Bot that re-tweets articles that have the hashtag ArtificialIntelligence

web bot for Twitter in python

Bots are a type of weak artificial intelligence. If you’ve enjoyed this post and want to learn more about artificial intelligence, check out my beginner’s guide here.

Love it? Pin it!
web bots and automation


Leave a Reply

Your email address will not be published.

%d bloggers like this: