Day 1 of India’s Lockdown: ME- Excited to learn lots of amazing technical stuff!
Day 5 of India’s Lockdown: ME-definitely I’m gonna start studying. Gonna go out of house as a data scientist for sure. But first, Let’s watch movies and sleep like a log.
Day 11 of India’s lockdown: This lockdown has kinda bored the hell out of me. Let’s forget about the dream of becoming a data scientist in 21 days, let’s just do some cool stuff with Python and show my family members about how great of a coder I am! Yup. Let’s do this.
So, We are gonna use messaging services of Way2SMS , and try to automate text messaging with python.
(the file you are about to use, was originally taken from Way2sms package by Shubham Choudhary , but the file has been modified by me, because the original one doesn’t work for current webpage of Way2sms.com)
- Internet connection is required.(*Obviously, duh!*)
- I was misinformed by some website that Way2sms.com provides 100 messages per day, and so I prepared codes for that particular website to share with you. But, sadly it allows only 2 messages per day for free(You can recharge your way2sms account to send text messages)
- You have to manually create an account in way2sms.com before using this tutorial, in case if you don’t have an account.
- First, we need to install Beautiful soup. Go to the terminal of your IDE, and type this to install bs4.
pip install beautifulsoup4
- Now, Download this python file : way2sms.py
- move it to your workspace/folder on which you are going to create a python file and write codes in it.
- Create a new python file (it’s name can be anything) in the same folder in which you have kept the downloaded file way2sms, and import the module way2sms in the current file:
- then, to let python login into the website, we will write:
q=way2sms.Sms(phonenumber,password) #the arguments passed to way2sms.Sms are of int type, not string.
if your credentials are correct, you will be logged in and you will see the statement ‘Successfully Logged in’ printed out.
- To send a SMS, type this:
look at this Example,
q.send('9876543210','Yo Mr.White , science yo!') #-----these are comments----- #Shoutout to Breaking bad fans! #the phone number written here is not mine, its just numbers in reversed order. Don't stalk anybody,you morons.
- To send a SMS later at a fixed date and time, use funtion send_later
q.send_later(9876543210, "Message body", 04/04/20, 20:05) #date must be in dd/mm/yyyy format #time must be in 24hr format. For ex: 18:05
- To check how many messages you’ve sent today, call the function
msgSentToday(). (You can write q.msgSentToday())
- At the end, it’s a good practice to logout.
There you go. Go show your siblings how cool you are! Have fun with coding.
Health is Wealth. Stay safe. Wash Your hands. Don’t go out.