“Automation” something us humans are trying to achieve since a long time. How do we define Automation? We can say it is by which the technology can perform a procedure without any human intervention. Yes, automation is the reason you can’t book your products in flash sales because we humans are slow, machines are fast and accurate.
Automation dates to 1620 where Cornelius Drebbel a Dutch scientist invented thermostat that automatically switches on or off according to the temperature. Automation is widely used in industries for operating machinery. Automation can be achieved by using various means like
mechanical, electrical, hydraulic, pneumatic. So how can we automate things in our daily life? Do we need electrical equipment to automate the things? The answer is no. Many of our daily procedures gets done in front of a mere computer. So, if we can automate things on a computer machine we can say we automated our lifestyle.
What are the things you need to automate a computer? I’d say just a computer with python installed. Yes, it’s that simple. Having some basic python knowledge will help you along the way or maybe you will learn while doing it. Let me tell you the things you could perform by using
Sending automated text messages using python and Twilio: As you see there are so many possibilities it’s not viable to discuss how to do all
those step by step, but I’ll teach you how to send automated text messages as an introduction. So, the first thing I want you to do is visit https://www.python.org/downloads/ download the latest version based on your operating system. Install the software from the file downloaded. To ensure python is installed correctly on your machine open your terminal and type python and hit enter. You can see the
python interpreter opens in your terminal which is waiting for your input at >>>.
You can also see the version of the python that has been installed.
We do use IDE for our convenience to write programs and we are lucky that python installs one for us when we install their software. To open the IDE for python type “IDLE” in your search box on the windows machine and open it. Now you can write the program in the IDLE and save it in a file and can execute it from there.
So, the service we are going to use to send automated text messages from your computer to your mobile is Twilio. The free account of Twilio lets you to send a limited number of messages per month. Next visit http://twilio.com and signup. After signing up You need to install the
Twilio module on your machine to use it in your python program. The python installation comes with “pip” which lets you download modules that are required for your python program. So open your terminal and type in the command “pip install Twilio”. This will install the Twilio module on to your machine. Next, we can start writing our first python program. Fire up your IDE and start writing the
>>>from twilio.rest import TwilioRestClient – (1)
>>>accountSID = ‘xxxxxxxxxxxxxxxxxxxxxxxxxx’ – (2)
>>>authToken = ‘xxxxxxxxxxxxxxxxxxxxxxxxxx’ – (3)
>>>twilioCli = TwilioRestClient(accountSID, authToken) – (4)
>>>myTwilioNumber = ‘+91XXXXXXXXXX’ – (5)
>>>myCellPhone = ‘+91XXXXXXXXXX – (6)
>>>message = twilioCli.messages.create(body = ‘hello Surya how are you’,
from_=myTwilioNumber, to=myCellPhone) – (7)
I’ll explain the code by each line. The first line of the code lets you import the Twilio module into your program. After signing up in twilio the user will be provided with a phone number, account SID and the auth token on their dashboard. Copy the account SID and auth token and paste them in their values in line 2 and 3. The TwilioRestClient object that is returned by the TwilioRestClient() has a messages attribute. Copy your Twilio number and phone number into myTwilioNumber and myCellPhone respectively in 5 and 6. The create method will allow you to send the text body and takes your Twilio number and phone number as an argument to send the text. That’s it!
You can insert this code to any of your programs to notify the completion of the program
execution or you can use it as an event handler is any certain action takes place in your program. The
things you can do with automation are plenty and this is just an example. Happy learning!.