I built a twitter bot

For some time I have been trying to learn Python, a programming language that is easy to use and the preferred one for many network engineers taking the first steps on automation. I read some books, watch some youtube videos and create some dumb scripts. But what really helps is creating a project, however small it is and doing it from start to finish. So, I decided to build a twitter bot.

A bot is a software that executes some repetitive task fully automated and without human interaction. In this particular case I made a bot that publishes my country’s CoVid-19 statistics 2 times a day to a twitter account. You can see it in action checking out @Covid19AO_Stats. The stats are captured every day from the official CoVid-19 site for Angola, http://www.covid19.gov.ao.

Covid19 Angola twitter bot
CoVid19 Angola twitter bot

For this project I decided to join together my studies of Python with my curiosity around how easy it is to build applications on the cloud. A lot of people say it is easy, lots more say it is cheap. Nothing better than trying it and getting to my own conclusions.

Architecture

The figure below shows the architecture for the project. To build this bot I used Amazon Web Services (AWS) but I believe that this could be done with the equivalent services from other cloud providers.

Architecture for the @CoVid19AO_Stats bot

I could set up an instance (this is what AWS calls a virtual machine) working 24 hours a day that would run my code at pre-defined times like a cronjob for example. But that is just too old-school. The central service for the project is AWS Lambda. AWS Lambda allows us to run code without the need to provision or run servers. This is what makes it serverless.

I configured the Lambda function with a Python 3.6 runtime. The code connects to the server, downloads the web page, processes the values and posts them on witter using its API. With Cloudwatch Events I make the function trigger and run at the time I want or at regular intervals without having to login and do it manually. Simple right?

What next?

This little bot was done as a simple study exercise putting together different elements that I am curious about: Python, webscraping, serverless and cloud. For now I don’t have any other plans or objectives for it, like financial.

What do you think of it? Anything else to make it better? Do you feel inspired to make something similar?


The bot @Covid19AO_Stats
https://twitter.com/Covid19AO_Stats

AWS Lambda
https://aws.amazon.com/lambda/

What is the cloud?
http://www.mariopinho.com/en/what-is-cloud/

Leave a Reply

Your email address will not be published. Required fields are marked *