Being a popular general-purpose programming Python offers many functionalities and has many applications. Python has amazing libraries using which you can automate many things. Today we will be looking into the code examples of Pywhatkit python module which automates –
- WhatsApp messages
- Playing a Video on YouTube
- Google search
- Fetch the information on a topic
What is Pywhatkit?
Pywhatkit python module allows you to automate WhatsApp messages and other cool stuff. It also used to automate things like playing a video, searching in google, shut down your PC and much more.
The fun is you can do all this automation with just a couple of lines of code. That’s why we love it more. Well, I can understand your excitement and without much delay, let’s roll!!!
First things first – Install the Pywhatkit package.
pip install pywhatkit
Run this code in the command prompt to install the Pywhatkit package. We are all set to Automate things now.
Automate WhatsApp message with Pywhatkit code example
As I said earlier, using Pywhatkit you can automate WhatsApp messages. Now, let’s go through that simplest way to automate the message using the WhatsApp webpage to any given number. All you need to do is to log in to your WhatsApp webpage in the browser. If you are done with this, good to go.
Number = The receivers WhatsApp number.
Message = The input message that you want to send.
Hours = Time (Hour) of message delivery (Should be in 24 hours formst)
Minutes = Time (Minutes) of message delivery
Now, let’s import the required module i.e. Pywhatkit into the editor.
#Importing module Import pywhatkit
Hello from the creator of pywhatkit, Ankit Raj Mahapatra. Kindly do report bugs if any What's new: 1. Fixed text_to_handwriting() function. 2. Added pywhatkit.help.<function name> for ease of use. 3. Added feature to schedule message in a group.
After successful importing, you can see a message from the creator. Thanks to Ankit for such a wonderful python library.
# importing the module import pywhatkit # sending message to reciever # using pywhatkit pywhatkit.sendwhatmsg("+91xxxxxxxxxx","Greetings from HackAnons",22,43)
In 63 seconds web.whatsapp.com will open and after 20 seconds message will be delivered
Wow! We have automatically sent a WhatsApp message using the Pywhatkit module in python. As you can see after the execution of the code, it will print a line which informs you about the message delivery.
Play a YouTube Video Using Pywhatkit python
Pywhatkit offers another functionality i.e. pywhatkit.playonyt(). Using this function, you can automatically play a YouTube video by specifying its name or the topic. Either will work fine.
pywhatkit.playonyt("url / topic")
url / Topic = The url or the topic of the video you want to play on YouTube.
It is a very simple syntax and now let’s play a video on YouTube using Pywhatkit.playonyt() function.
# importing the module import pywhatkit pywhatkit.playonyt("HackAnons - Automate whatsapp messages")
After you run this code by specifying the Topic as I did here, it will fetch you the URL of the video in just seconds.
There it is. I have specified the topic and name and Pywhatkit python has returned what I have asked! And all these will happen in seconds and all it needs is a line of code!
Automated Google search using Pywhatkit python
We have automated multiple things. Another cool automation that Pywhatkit python offers is an automated google search. You can use pywhatkit.search() function to search for anything on Google. You can also make use of pywhatkit.info() function to get information about the topic as well.
Let’s see how it works.
# importing the module import pywhatkit #Returns the google search pywhatkit.search("HackAnons")
The result shows the google search of the input topic name. It is precise in its efforts and returns what you have asked.
Now, let’s see how we can extract a piece of information from the web using pywhatkit.info() function.
Topic = The topic on that you want to extract the information.
Lines = How much information you want to extract.
# importing the module import pywhatkit pywhatkit.info('ibm',lines=4)
International Business Machines Corporation (IBM) is an American multinational technology and consulting company headquartered in Armonk, New York, with more than 350,000 employees serving clients in 170 countries. On October 8, 2020 IBM announced it was spinning off the Managed Infrastructure Services unit of its Global Technology Services division into a new public company, an action expected to be completed by the end of 2021.
Whoo! here is our requested information.
Printed Text to Handwritten text using Pywhatkit
As the headline says, you can convert the printed text to handwritten text using the Pywhatkit python module. It offers a function names pywhatkit.handwritten() for this specific purpose. Let’s see how it works.
text = The input text which you want to convert as handwritten text.
rgb = The colour combination of the text in 0,0,0 RGB form.
import pywhatkit pywhatkit.text_to_handwriting('The Internet of Things (IoT) technology will connect the devices over the internet. The devices such as wearables, smartphones, sensors, and other devices will involve in active data collection which further can be used to increase the user experience and quality of the product.',rgb=[0,0,0])
Here it is. See how beautifully the input text converted into the handwritten text.
Convert an Image to ASCII Art using Pywhatkit python
The above headline can excite anybody. Yes, I am talking about pywhatkit.image_to_ascii_art() function in Pywhatkit. This function will take an image as input and converts it to ASCII art. Let’s see how it works.
Path = The path where the image is stored in your PC.
Output = The output converted file.
Great. Let’s convert an image into ASCII art with a single line of code.
#Imports the module import pywhatkit #Converts an image into ASCII art. pywhatkit.image_to_ascii_art('barak_obama.png','barak_obama.text')
Yes, It’s none other than one of the greatest presidents of the United Nation, Mr. Barak Obama. Such beautiful ASCII Art. Thanks to Pywhatkit.
Code less Automate more – Pywhatkit python module
Already we have automated many things using the Pywhatkit python module. All these illustrations are made using the code examples which is more important as far as your understanding is concerned.
Now, we can do some other automations such as –
- Shut down the PC – Shuts your PC down
- Show history – Returns all the messages sent through this library
Shut Down your PC
Yes, you can turn down your PC using the function pywhatkit.shutdown(). This will allow you to do the same within specified time.
Let’s see how it works.
#Imports the module import pywhatkit #Shuts your PC down in 100 seconds. pywhatkit.shutdown(time=100)
Here, you have to mention the time in seconds. After the function crashes at that specified time, it will shut down your PC. You can try this for FUN.
You can also use the pywhatkit.cancelShutdown() function to terminate your shut down request.
The pywhatkit.showHistory() function will return all the messages that sent through this module.
You can send files along with the text in WhatsApp using the pywhatkit.send_file() function.
The syntax for this will be –
pywhatkit.send_file(“+91##########”,”Path to file”,19,10)
Kindly consider this trying yourself for more understanding and work flow of the module.
The Pywhatkit python module is one of the popular modules for the Automation process. You can Automate WhatsApp messages, Play YouTube videos, Search on Google, and Extract data as well.
This article gives you Pywhatkit code examples for your easy understating as well as implementation. I hope you had great fun doing this and that’s all for now.