How To Automate Good Morning Text With Python

 


In this post, we are going to automate the good morning text using python. This means that we are going to be writing a python script to send morning greetings text at a particular time everyday. For this, we need to access one API Service and install two python libraries, which are TextbeltRequests and Schedule.

Textbelt

Textbelt is a website which offers sms automation. They have an Api which allows us to use their service to send messages. 

Requests

Requests is a python library which allows you to send a requests to access an API.

Schedule

Schedule is a python library which allows you to schedule a python script to run repeatedly at a particular time.

Having all those out of the way, let's get straight into coding. First, we have to install Requests and Schedule, to do that, we will type this in our terminal(for mac) or command prompt(form windows).
pip install requests schedule

After that, let's create a new python file and name it app.py, and we can paste the code below into that file.

import requests
import schedule
import time

def send_message():
	resp = requests.post('https://textbelt.com/text', {
    	'phone': 'your mobile number',
		'message': 'Hey, Good morning' ,
		'key': 'texbelt'
    })
    print(resp.json())
    
schedule.every().day.at('06:00').do(send_message)

while True:
	schedule.run_pending()
	time.sleep(l)
Now, i will explain the code above.
This code is importing the required libraries we need for this task:
import requests
import schedule
import time
This is the python function that is executed when we want to send a message:
def send_message():
	resp = requests.post('https://textbelt.com/text', {
    	'phone': 'your mobile number',
		'message': 'Hey, Good morning' ,
		'key': 'texbelt'
    })
    print(resp.json())
This code below just schedules the send_message function and executes it repeatedly:
schedule.every().day.at('06:00').do(send_message)

while True:
	schedule.run_pending()
	time.sleep(l)
Now, we can run out app.py file by going to our terminal(for mac) or command prompt(form windows) and run this command line below:.
python app.py
Everything should now be working perfectly.
That's all for this post, and i'll see you in the next one.

Post a Comment

1 Comments

  1. 888Casino Lake Tahoe Reviews & Prices | Mapyro
    888Casino Lake Tahoe is ranked number 1 in the world by U.S. 전라남도 출장샵 News & World Report as 김해 출장안마 a 여주 출장샵 Best Casino in Lake 문경 출장마사지 Tahoe. Check 보령 출장마사지 reviews, photos and reviews. Rating: 2.3 · ‎8 votes

    ReplyDelete