Automated WhatsApp Message using Python
Automated WhatsApp Message Using Python (pywhatkit)
GitHub: Git Profile, LinkedIn: Profile Link
Problem Statement
Whenever want to send WhatsApp Messages, For n Number of People Individually. It becomes very difficult & time-consuming process in order to overcome this problem, I came with the simple idea that can be used ease this process to save time & to reach more number of people in short period of time.
Objective
Let us consider a small business, where we have to reach to n number of customers with the help of Contract Number present in the Business Dataset (excel,csv etc.). Now problem that arises is that we can't save n number of people in our system (PC,Mobile), Even if we do so it is not possible to reach them out individually.
Methodology
To overcome this problem, I am using pywhatkit which is the Popular Python Library used for WhatsApp Message Automation, along with this I am also using the Pandas Library used for reading data from datasheets such as excel,csv etc. Methodology of the same is shown below step by step.
Step 1: Reading data from Excel Sheet using Pandas Lib.
Step 2: Store Phone Number Column from datasheet into List, let us say Mylist=data.at[:,"Phone_Num"].
Step 3: Since we want to Share Message to n number of people, Using Loop Statement that is for i in mylist.
Step 4: Now using Pywhatkit Lib. which is used to Automate this process with the function called sendwhatmsg(), Which takes Three arguments Phone Number, time in hour, time in minute.Every time we call this function, with different Contract Number from our list.
Solution
import pywhatkit as pwk
import pandas as pd
from datetime import datetime
'''Getting Time(Hour & Minute)'''
# Get the current date and time
current_time = datetime.now()
# Extract hour and minute
hour = current_time.hour
minute = current_time.minute
'''Reading Data From Dataset (Excel), using Pandas'''
data = pd.read_excel("contract_details.xlsx")
print(data) #data from dataset
mylist = list(data.loc[:,"Phone"])
count = 1;
for i in mylist:
# using Exception Handling to avoid unexpected errors
try:
# Send a Message to 'i'th phone in dataframe
pwk.sendwhatmsg("+91"+str(i), "Hi, how are you?", hour,minute+count)
count+=1
# Send an Image to a Contact with the no Caption
pwk.sendwhats_image("+91"+str(i), "hello.jpeg")
print("Message Sent!") #Prints success message in console
# error message
except:
print("Error in sending the message")
Find More Details on GitHub: Source Code
Comments
Post a Comment